( keys: Array<string>, hotkey: Array<KeyboardKey>, )
| 48 | |
| 49 | /** Checks if the currently pressed keys match any of the hotkey permutations */ |
| 50 | export const isHotkeyCombinationPressed = ( |
| 51 | keys: Array<string>, |
| 52 | hotkey: Array<KeyboardKey>, |
| 53 | ): boolean => { |
| 54 | const permutations = getHotkeyPermutations(hotkey) |
| 55 | const pressedKeys = keys.map((key) => key.toUpperCase()) |
| 56 | |
| 57 | return permutations.some( |
| 58 | (combo) => |
| 59 | // every key in the combo must be pressed |
| 60 | combo.every((key) => pressedKeys.includes(String(key).toUpperCase())) && |
| 61 | // and no extra keys beyond the combo |
| 62 | pressedKeys.every((key) => |
| 63 | combo.map((k) => String(k).toUpperCase()).includes(key), |
| 64 | ), |
| 65 | ) |
| 66 | } |
no test coverage detected