added fallback for no key location code (not just android)

should fix some of the result validation errors
This commit is contained in:
Miodec 2023-04-13 15:23:12 +02:00
parent c69d2d0251
commit 3e95164703
2 changed files with 15 additions and 15 deletions

View file

@ -993,9 +993,8 @@ $("#wordsInput").keydown((event) => {
const now = performance.now();
setTimeout(() => {
const isAndroid =
event.key === "Unidentified" && event.code === "" && event.which === 229;
TestInput.recordKeydownTime(now, isAndroid ? "Android" : event.code);
const eventCode = event.code === "" ? "NoCode" : event.code;
TestInput.recordKeydownTime(now, eventCode);
}, 0);
});
@ -1010,11 +1009,12 @@ $("#wordsInput").keyup((event) => {
event.code = "Space"; //powertoys bug
}
event.code = "";
const now = performance.now();
setTimeout(() => {
const isAndroid =
event.key === "Unidentified" && event.code === "" && event.which === 229;
TestInput.recordKeyupTime(now, isAndroid ? "Android" : event.code);
const eventCode = event.code === "" ? "NoCode" : event.code;
TestInput.recordKeyupTime(now, eventCode);
}, 0);
});

View file

@ -67,7 +67,7 @@ const keysToTrack = [
"Period",
"Slash",
"Space",
"Android", //smells
"NoCode", //android (smells) and some keyboards might send no location data - need to use this as a fallback
];
interface Keypress {
@ -318,14 +318,14 @@ export function forceKeyup(now: number): void {
}
}
let androidIndex = 0;
let noCodeIndex = 0;
export function recordKeyupTime(now: number, key: string): void {
if (!keysToTrack.includes(key)) return;
if (key === "Android") {
androidIndex--;
key = "Android" + androidIndex;
if (key === "NoCode") {
noCodeIndex--;
key = "NoCode" + noCodeIndex;
}
if (keyDownData[key] === undefined) return;
@ -351,9 +351,9 @@ export function recordKeydownTime(now: number, key: string): void {
return;
}
if (key === "Android") {
key = "Android" + androidIndex;
androidIndex++;
if (key === "NoCode") {
key = "NoCode" + noCodeIndex;
noCodeIndex++;
}
if (keyDownData[key] !== undefined) {
@ -431,7 +431,7 @@ export function resetKeypressTimings(): void {
lastStartTime: -1,
};
keyDownData = {};
androidIndex = 0;
noCodeIndex = 0;
if (spacingDebug) {
console.clear();
if (spacingDebug) {