MCPcopy Create free account
hub / github.com/Monogatari/Monogatari / keyboardShortcut

Function keyboardShortcut

src/engine/input.ts:6–17  ·  view source on GitHub ↗
(engine: VisualNovelEngine, shortcut: string | string[], callback: (this: VisualNovelEngine, event: KeyboardEvent, element: DOM) => void)

Source from the content-addressed store, hash-verified

4import mousetrap, { ExtendedKeyboardEvent } from 'mousetrap';
5
6export 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
19export 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 };

Callers 1

registerListenerFunction · 0.85

Calls 2

bindMethod · 0.45
applyMethod · 0.45

Tested by

no test coverage detected