Created
January 12, 2025 20:13
-
-
Save ova2/f8bf5c81f88b54971b52a3f9d0d77599 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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