UNPKG

1.84 kBTypeScriptView Raw
1// Type definitions for Mousetrap 1.6
2// Project: http://craig.is/killing/mice
3// Definitions by: Dániel Tar <https://github.com/qcz>
4// Alan Choi <https://github.com/alanhchoi>
5// Nic Barker <https://github.com/nicbarker>
6// Piotr Błażejewicz <https://github.com/peterblazejewicz>
7// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
8
9declare namespace Mousetrap {
10 interface ExtendedKeyboardEvent extends KeyboardEvent {
11 returnValue: boolean; // IE returnValue
12 }
13
14 interface MousetrapStatic {
15 (el?: Element): MousetrapInstance;
16 new (el?: Element): MousetrapInstance;
17 addKeycodes(keycodes: { [key: number]: string }): void;
18 stopCallback: (e: ExtendedKeyboardEvent, element: Element, combo: string) => boolean;
19 bind(
20 keys: string | string[],
21 callback: (e: ExtendedKeyboardEvent, combo: string) => any,
22 action?: string,
23 ): MousetrapInstance;
24 unbind(keys: string | string[], action?: string): MousetrapInstance;
25 trigger(keys: string, action?: string): MousetrapInstance;
26 reset(): MousetrapInstance;
27 }
28
29 interface MousetrapInstance {
30 stopCallback: (e: ExtendedKeyboardEvent, element: Element, combo: string) => boolean;
31 bind(
32 keys: string | string[],
33 callback: (e: ExtendedKeyboardEvent, combo: string) => any,
34 action?: string,
35 ): this;
36 unbind(keys: string | string[], action?: string): this;
37 trigger(keys: string, action?: string): this;
38 handleKey(character: string, modifiers: string[], e: ExtendedKeyboardEvent): void;
39 reset(): this;
40 }
41}
42
43declare const Mousetrap: Mousetrap.MousetrapStatic;
44
45export = Mousetrap;
46
47export as namespace Mousetrap;