Skip to content

Instantly share code, notes, and snippets.

@ova2
Created January 12, 2025 20:13
Show Gist options
  • Save ova2/f8bf5c81f88b54971b52a3f9d0d77599 to your computer and use it in GitHub Desktop.
Save ova2/f8bf5c81f88b54971b52a3f9d0d77599 to your computer and use it in GitHub Desktop.
private checkPressedKeys(keyboardEvents: KeyboardEvent[], pressedKeysSize: number) {
if (pressedKeysSize === 0) {
// all keys have been released by "keyup" => inform subscribers
return true;
} else if (keyboardEvents.length === pressedKeysSize) {
// check for the exactly count of pressed shortcut keys is important
// also the sequence of the key presses is important => check the order
const sorted = [...keyboardEvents]
.sort((event1, event2) => (event1.timeStamp < event2.timeStamp ? -1 : 1))
.map(event1 => event1.code)
.join();
return sorted === keyboardEvents.map(event => event.code).join();
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment