From d446fd5b669ebc897bcea73c11f8c7b48c073788 Mon Sep 17 00:00:00 2001 From: Miodec Date: Wed, 5 Apr 2023 13:09:46 +0200 Subject: [PATCH] added special key tracking for android and its special way of defining keydown and keyup events --- .../src/ts/controllers/input-controller.ts | 12 ++++++++-- frontend/src/ts/test/test-input.ts | 24 +++++++++++++++---- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/frontend/src/ts/controllers/input-controller.ts b/frontend/src/ts/controllers/input-controller.ts index bc2473976..43eaa19a9 100644 --- a/frontend/src/ts/controllers/input-controller.ts +++ b/frontend/src/ts/controllers/input-controller.ts @@ -966,14 +966,22 @@ $(document).keydown(async (event) => { }); $("#wordsInput").keydown((event) => { + if (event.originalEvent?.repeat) return; + setTimeout(() => { - TestInput.recordKeydownTime(event.code); + const isAndroid = + event.key === "Unidentified" && event.code === "" && event.which === 229; + TestInput.recordKeydownTime(isAndroid ? "Android" : event.code); }, 0); }); $("#wordsInput").keyup((event) => { + if (event.originalEvent?.repeat) return; + setTimeout(() => { - TestInput.recordKeyupTime(event.code); + const isAndroid = + event.key === "Unidentified" && event.code === "" && event.which === 229; + TestInput.recordKeyupTime(isAndroid ? "Android" : event.code); }, 0); }); diff --git a/frontend/src/ts/test/test-input.ts b/frontend/src/ts/test/test-input.ts index f298b1a46..e3986587b 100644 --- a/frontend/src/ts/test/test-input.ts +++ b/frontend/src/ts/test/test-input.ts @@ -50,6 +50,7 @@ const keysToTrack = [ "Period", "Slash", "Space", + "Android", //smells ]; interface Keypress { @@ -298,10 +299,18 @@ export function forceKeyup(): void { } } +let androidIndex = 0; + export function recordKeyupTime(key: string): void { - if (keyDownData[key] === undefined || !keysToTrack.includes(key)) { - return; + if (!keysToTrack.includes(key)) return; + + if (key === "Android") { + androidIndex--; + key = "Android" + androidIndex; } + + if (keyDownData[key] === undefined) return; + const now = performance.now(); const diff = Math.abs(keyDownData[key].timestamp - now); keypressTimings.duration.array[keyDownData[key].index] = diff; @@ -311,9 +320,15 @@ export function recordKeyupTime(key: string): void { } export function recordKeydownTime(key: string): void { - if (keyDownData[key] !== undefined || !keysToTrack.includes(key)) { - return; + if (!keysToTrack.includes(key)) return; + + if (key === "Android") { + key = "Android" + androidIndex; + androidIndex++; } + + if (keyDownData[key] !== undefined) return; + keyDownData[key] = { timestamp: performance.now(), index: keypressTimings.duration.array.length, @@ -369,6 +384,7 @@ export function resetKeypressTimings(): void { lastStartTime: -1, }; keyDownData = {}; + androidIndex = 0; if (spacingDebug) console.clear(); }