summaryrefslogtreecommitdiff
path: root/packages/client/src/scripts/touch.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/client/src/scripts/touch.ts')
-rw-r--r--packages/client/src/scripts/touch.ts19
1 files changed, 19 insertions, 0 deletions
diff --git a/packages/client/src/scripts/touch.ts b/packages/client/src/scripts/touch.ts
new file mode 100644
index 0000000000..06b4f8b2ed
--- /dev/null
+++ b/packages/client/src/scripts/touch.ts
@@ -0,0 +1,19 @@
+const isTouchSupported = 'maxTouchPoints' in navigator && navigator.maxTouchPoints > 0;
+
+export let isTouchUsing = false;
+
+export let isScreenTouching = false;
+
+if (isTouchSupported) {
+ window.addEventListener('touchstart', () => {
+ // maxTouchPointsなどでの判定だけだと、「タッチ機能付きディスプレイを使っているがマウスでしか操作しない」場合にも
+ // タッチで使っていると判定されてしまうため、実際に一度でもタッチされたらtrueにする
+ isTouchUsing = true;
+
+ isScreenTouching = true;
+ }, { passive: true });
+
+ window.addEventListener('touchend', () => {
+ isScreenTouching = false;
+ }, { passive: true });
+}