UNPKG

1.88 kBTypeScriptView Raw
1export interface IKeyCodeTable {
2 [code: number]: string;
3}
4export interface IKeyCodeReverseTable {
5 [key: string]: number;
6}
7export interface IKeyMap {
8 [key: string]: string;
9}
10export declare const KeyCodes: IKeyCodeTable;
11export declare const Modifiers: IKeyCodeTable;
12export declare const ModifierBitMasks: IKeyCodeReverseTable;
13export declare const Aliases: IKeyMap;
14export declare const ShiftKeys: IKeyMap;
15export interface IKeyCombo {
16 key?: string;
17 modifiers: number;
18}
19export declare function comboMatches(a: IKeyCombo, b: IKeyCombo): boolean;
20/**
21 * Converts a key combo string into a key combo object. Key combos include
22 * zero or more modifier keys, such as `shift` or `alt`, and exactly one
23 * action key, such as `A`, `enter`, or `left`.
24 *
25 * For action keys that require a shift, e.g. `@` or `|`, we inlude the
26 * necessary `shift` modifier and automatically convert the action key to the
27 * unshifted version. For example, `@` is equivalent to `shift+2`.
28 */
29export declare const parseKeyCombo: (combo: string) => IKeyCombo;
30/**
31 * Converts a keyboard event into a valid combo prop string
32 */
33export declare const getKeyComboString: (e: KeyboardEvent) => string;
34/**
35 * Determines the key combo object from the given keyboard event. Again, a key
36 * combo includes zero or more modifiers (represented by a bitmask) and one
37 * action key, which we determine from the `e.which` property of the keyboard
38 * event.
39 */
40export declare const getKeyCombo: (e: KeyboardEvent) => IKeyCombo;
41/**
42 * Splits a key combo string into its constituent key values and looks up
43 * aliases, such as `return` -> `enter`.
44 *
45 * Unlike the parseKeyCombo method, this method does NOT convert shifted
46 * action keys. So `"@"` will NOT be converted to `["shift", "2"]`).
47 */
48export declare const normalizeKeyCombo: (combo: string, platformOverride?: string) => string[];