(engine: VisualNovelEngine, shortcut: string | string[], callback: (this: VisualNovelEngine, event: KeyboardEvent, element: DOM) => void)
| 4 | import mousetrap, { ExtendedKeyboardEvent } from 'mousetrap'; |
| 5 | |
| 6 | export function keyboardShortcut (engine: VisualNovelEngine, shortcut: string | string[], callback: (this: VisualNovelEngine, event: KeyboardEvent, element: DOM) => void): void { |
| 7 | engine.debug.log (`Binding Keyboard Shortcut: ${shortcut}`); |
| 8 | |
| 9 | mousetrap.bind (shortcut, (event: ExtendedKeyboardEvent) => { |
| 10 | const target = event.target as HTMLElement | null; |
| 11 | |
| 12 | if (target && target.tagName?.toLowerCase () !== 'input') { |
| 13 | event.preventDefault (); |
| 14 | callback.apply (engine, [event, $_(target)]); |
| 15 | } |
| 16 | }); |
| 17 | } |
| 18 | |
| 19 | export function registerListener (engine: VisualNovelEngine, name: string, listener: { keys?: string | string[]; callback: (this: VisualNovelEngine, event: Event, element: DOM) => unknown }, replace = false): void { |
| 20 | const listenerWithName = { ...listener, name }; |
no test coverage detected