moved function calls to their own events

returning if key is not tracked
returning if key is already pressed (not tracking repeats)
only pushing alpha numerics and space
This commit is contained in:
Miodec 2023-03-29 17:11:48 +02:00
parent 6a79eb6ded
commit 4fe1f97c66
2 changed files with 17 additions and 5 deletions

View file

@ -834,9 +834,6 @@ $(document).keydown(async (event) => {
}
TestInput.recordKeypressSpacing();
TestInput.setKeypressDuration(performance.now());
setTimeout(() => {
TestInput.recordKeydownTime(event.code);
}, 0);
TestInput.setKeypressNotAfk();
//blocking firefox from going back in history with backspace
@ -950,6 +947,18 @@ $(document).keydown(async (event) => {
isBackspace = event.key === "Backspace" || event.key === "delete";
});
$("#wordsInput").keydown((event) => {
setTimeout(() => {
TestInput.recordKeydownTime(event.code);
}, 0);
});
$("#wordsInput").keyup((event) => {
setTimeout(() => {
TestInput.recordKeyupTime(event.code);
}, 0);
});
$("#wordsInput").keyup((event) => {
if (!event.originalEvent?.isTrusted || TestUI.testRestarting) {
event.preventDefault();
@ -966,7 +975,6 @@ $("#wordsInput").keyup((event) => {
);
TestInput.pushKeypressDuration(diff);
}
TestInput.recordKeyupTime(event.code);
TestInput.setKeypressDuration(now);
Monkey.stop();
});

View file

@ -239,15 +239,19 @@ export function setKeypressDuration(val: number): void {
let newKeypresDurationArray: number[] = [];
export function recordKeyupTime(key: string): void {
if (keysObj[key] === undefined) return;
const now = performance.now();
const diff = Math.abs(keysObj[key] - now);
newKeypresDurationArray.push(roundTo2(diff));
if (/(Key[A-Z])|(Digit[0-9])|Space/.test(key)) {
newKeypresDurationArray.push(roundTo2(diff));
}
delete keysObj[key];
updateOverlap();
}
export function recordKeydownTime(key: string): void {
if (keysObj[key] !== undefined) return;
keysObj[key] = performance.now();
updateOverlap();