UNPKG

7.97 kBTypeScriptView Raw
1export declare type KeySequence = KeyCode[];
2export declare namespace KeySequence {
3 function equals(a: KeySequence, b: KeySequence): boolean;
4 enum CompareResult {
5 NONE = 0,
6 PARTIAL = 1,
7 SHADOW = 2,
8 FULL = 3
9 }
10 function compare(a: KeySequence, b: KeySequence): CompareResult;
11 function parse(keybinding: string): KeySequence;
12}
13/**
14 * The key sequence for this binding. This key sequence should consist of one or more key strokes. Key strokes
15 * consist of one or more keys held down at the same time. This should be zero or more modifier keys, and zero or one other key.
16 * Since `M2+M3+<Key>` (Alt+Shift+<Key>) is reserved on MacOS X for writing special characters, such bindings are commonly
17 * undefined for platform MacOS X and redefined as `M1+M3+<Key>`. The rule applies on the `M3+M2+<Key>` sequence.
18 */
19export interface Keystroke {
20 readonly first?: Key;
21 readonly modifiers?: KeyModifier[];
22}
23export interface KeyCodeSchema {
24 key?: Partial<Key>;
25 ctrl?: boolean;
26 shift?: boolean;
27 alt?: boolean;
28 meta?: boolean;
29 character?: string;
30}
31/**
32 * Representation of a pressed key combined with key modifiers.
33 */
34export declare class KeyCode {
35 readonly key: Key | undefined;
36 readonly ctrl: boolean;
37 readonly shift: boolean;
38 readonly alt: boolean;
39 readonly meta: boolean;
40 readonly character: string | undefined;
41 constructor(schema: KeyCodeSchema);
42 /**
43 * Return true if this KeyCode only contains modifiers.
44 */
45 isModifierOnly(): boolean;
46 /**
47 * Return true if the given KeyCode is equal to this one.
48 */
49 equals(other: KeyCode): boolean;
50 toString(): string;
51 /**
52 * Create a KeyCode from one of several input types.
53 */
54 static createKeyCode(input: KeyboardEvent | Keystroke | KeyCodeSchema | string, eventDispatch?: 'code' | 'keyCode'): KeyCode;
55 private static keybindings;
56 static resetKeyBindings(): void;
57 /**
58 * Parses a string and returns a KeyCode object.
59 * @param keybinding String representation of a keybinding
60 */
61 static parse(keybinding: string): KeyCode;
62}
63export declare namespace KeyCode {
64 /**
65 * Determines a `true` of `false` value for the key code argument.
66 */
67 type Predicate = (keyCode: KeyCode) => boolean;
68 function isModifierString(key: string): boolean;
69 /**
70 * Different scopes have different execution environments. This means that they have different built-ins
71 * (different global object, different constructors, etc.). This may result in unexpected results. For instance,
72 * `[] instanceof window.frames[0].Array` will return `false`, because `Array.prototype !== window.frames[0].Array`
73 * and arrays inherit from the former.
74 * See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/instanceof
75 *
76 * Note: just add another check if the current `event.type` checking is insufficient.
77 */
78 function isKeyboardEvent(event: object & {
79 readonly type?: string;
80 }): event is KeyboardEvent;
81 /**
82 * Determine the pressed key of a keyboard event. This key should correspond to the physical key according
83 * to a standard US keyboard layout. International keyboard layouts are handled by `KeyboardLayoutService`.
84 *
85 * `keyIdentifier` is used to access this deprecated field:
86 * https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyIdentifier
87 */
88 function toKey(event: KeyboardEvent, dispatch?: 'code' | 'keyCode'): Key;
89 /**
90 * Determine the actual printable character that is generated from a pressed key.
91 * If the key does not correspond to a printable character, `undefined` is returned.
92 * The result may be altered by modifier keys.
93 */
94 function toCharacter(event: KeyboardEvent): string | undefined;
95}
96export declare enum KeyModifier {
97 /**
98 * M1 is the COMMAND key on MacOS X, and the CTRL key on most other platforms.
99 */
100 CtrlCmd = "M1",
101 /**
102 * M2 is the SHIFT key.
103 */
104 Shift = "M2",
105 /**
106 * M3 is the Option key on MacOS X, and the ALT key on most other platforms.
107 */
108 Alt = "M3",
109 /**
110 * M4 is the CTRL key on MacOS X, and is undefined on other platforms.
111 */
112 MacCtrl = "M4"
113}
114export declare namespace KeyModifier {
115 /**
116 * The CTRL key, independently of the platform.
117 * _Note:_ In general `KeyModifier.CtrlCmd` should be preferred over this constant.
118 */
119 const CTRL: KeyModifier.MacCtrl | KeyModifier.CtrlCmd;
120 /**
121 * An alias for the SHIFT key (`KeyModifier.Shift`).
122 */
123 const SHIFT: KeyModifier.Shift;
124 /**
125 * `true` if the argument represents a modifier. Otherwise, `false`.
126 */
127 function isModifier(key: string | undefined): boolean;
128}
129export interface Key {
130 readonly code: string;
131 readonly keyCode: number;
132 readonly easyString: string;
133}
134export declare namespace SpecialCases {
135 const META = "meta";
136 const CTRLCMD = "ctrlcmd";
137}
138export declare namespace Key {
139 function isKey(arg: unknown): arg is Key;
140 function getKey(arg: string | number): Key | undefined;
141 function isModifier(arg: string | number): boolean;
142 function equals(key: Key, keyCode: KeyCode): boolean;
143 const BACKSPACE: Key;
144 const TAB: Key;
145 const ENTER: Key;
146 const ESCAPE: Key;
147 const SPACE: Key;
148 const PAGE_UP: Key;
149 const PAGE_DOWN: Key;
150 const END: Key;
151 const HOME: Key;
152 const ARROW_LEFT: Key;
153 const ARROW_UP: Key;
154 const ARROW_RIGHT: Key;
155 const ARROW_DOWN: Key;
156 const INSERT: Key;
157 const DELETE: Key;
158 const SHIFT_LEFT: Key;
159 const SHIFT_RIGHT: Key;
160 const CONTROL_LEFT: Key;
161 const CONTROL_RIGHT: Key;
162 const ALT_LEFT: Key;
163 const ALT_RIGHT: Key;
164 const CAPS_LOCK: Key;
165 const OS_LEFT: Key;
166 const OS_RIGHT: Key;
167 const DIGIT0: Key;
168 const DIGIT1: Key;
169 const DIGIT2: Key;
170 const DIGIT3: Key;
171 const DIGIT4: Key;
172 const DIGIT5: Key;
173 const DIGIT6: Key;
174 const DIGIT7: Key;
175 const DIGIT8: Key;
176 const DIGIT9: Key;
177 const KEY_A: Key;
178 const KEY_B: Key;
179 const KEY_C: Key;
180 const KEY_D: Key;
181 const KEY_E: Key;
182 const KEY_F: Key;
183 const KEY_G: Key;
184 const KEY_H: Key;
185 const KEY_I: Key;
186 const KEY_J: Key;
187 const KEY_K: Key;
188 const KEY_L: Key;
189 const KEY_M: Key;
190 const KEY_N: Key;
191 const KEY_O: Key;
192 const KEY_P: Key;
193 const KEY_Q: Key;
194 const KEY_R: Key;
195 const KEY_S: Key;
196 const KEY_T: Key;
197 const KEY_U: Key;
198 const KEY_V: Key;
199 const KEY_W: Key;
200 const KEY_X: Key;
201 const KEY_Y: Key;
202 const KEY_Z: Key;
203 const MULTIPLY: Key;
204 const ADD: Key;
205 const DECIMAL: Key;
206 const SUBTRACT: Key;
207 const DIVIDE: Key;
208 const F1: Key;
209 const F2: Key;
210 const F3: Key;
211 const F4: Key;
212 const F5: Key;
213 const F6: Key;
214 const F7: Key;
215 const F8: Key;
216 const F9: Key;
217 const F10: Key;
218 const F11: Key;
219 const F12: Key;
220 const F13: Key;
221 const F14: Key;
222 const F15: Key;
223 const F16: Key;
224 const F17: Key;
225 const F18: Key;
226 const F19: Key;
227 const F20: Key;
228 const F21: Key;
229 const F22: Key;
230 const F23: Key;
231 const F24: Key;
232 const NUM_LOCK: Key;
233 const SEMICOLON: Key;
234 const EQUAL: Key;
235 const COMMA: Key;
236 const MINUS: Key;
237 const PERIOD: Key;
238 const SLASH: Key;
239 const BACKQUOTE: Key;
240 const INTL_RO: Key;
241 const BRACKET_LEFT: Key;
242 const BACKSLASH: Key;
243 const BRACKET_RIGHT: Key;
244 const QUOTE: Key;
245 const INTL_BACKSLASH: Key;
246 const INTL_YEN: Key;
247 const MAX_KEY_CODE: number;
248}
249export declare type KeysOrKeyCodes = Key | KeyCode | (Key | KeyCode)[];
250export declare namespace KeysOrKeyCodes {
251 const toKeyCode: (keyOrKeyCode: Key | KeyCode) => KeyCode;
252 const toKeyCodes: (keysOrKeyCodes: KeysOrKeyCodes) => KeyCode[];
253}
254//# sourceMappingURL=keys.d.ts.map
\No newline at end of file