UNPKG

1.53 kBTypeScriptView Raw
1declare namespace Mousetrap {
2 interface ExtendedKeyboardEvent extends KeyboardEvent {
3 returnValue: boolean; // IE returnValue
4 }
5
6 interface MousetrapStatic {
7 (el?: Element): MousetrapInstance;
8 new(el?: Element): MousetrapInstance;
9 addKeycodes(keycodes: { [key: number]: string }): void;
10 stopCallback: (e: ExtendedKeyboardEvent, element: Element, combo: string) => boolean;
11 bind(
12 keys: string | string[],
13 // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
14 callback: (e: ExtendedKeyboardEvent, combo: string) => boolean | void,
15 action?: string,
16 ): MousetrapInstance;
17 unbind(keys: string | string[], action?: string): MousetrapInstance;
18 trigger(keys: string, action?: string): MousetrapInstance;
19 reset(): MousetrapInstance;
20 }
21
22 interface MousetrapInstance {
23 stopCallback: (e: ExtendedKeyboardEvent, element: Element, combo: string) => boolean;
24 bind(
25 keys: string | string[],
26 callback: (e: ExtendedKeyboardEvent, combo: string) => void,
27 action?: string,
28 ): this;
29 unbind(keys: string | string[], action?: string): this;
30 trigger(keys: string, action?: string): this;
31 handleKey(character: string, modifiers: string[], e: ExtendedKeyboardEvent): void;
32 reset(): this;
33 }
34}
35
36declare const Mousetrap: Mousetrap.MousetrapStatic;
37
38export = Mousetrap;
39
40export as namespace Mousetrap;