use-normalized-keys
Version:
A React hook with unified API and 60fps animations for normalized keyboard input handling, designed for productivity applications, drawing tools, and professional interfaces
148 lines • 4.35 kB
TypeScript
/**
* Normalized Key Constants
*
* This module provides TypeScript constants for all normalized key values
* to improve developer experience and reduce errors when setting up sequences.
*
* Instead of guessing key names, import these constants:
*
* @example
* ```typescript
* import { Keys } from 'use-normalized-keys';
*
* // ✅ Good - Type-safe and clear
* holdSequence('brush-pressure', Keys.b, 800)
* comboSequence('save-file', [Keys.CONTROL, Keys.s], { timeout: 500 })
*
* // ❌ Avoid - Error-prone
* holdSequence('brush-pressure', ' ', 800) // Should be 'b'
* comboSequence('save-file', ['ctrl', 's']) // Should use Keys constants
* ```
*/
/**
* All normalized key constants organized by category
*/
export declare const Keys: {
readonly SPACE: "Space";
readonly ENTER: "Enter";
readonly TAB: "Tab";
readonly ESCAPE: "Escape";
readonly BACKSPACE: "Backspace";
readonly DELETE: "Delete";
readonly ARROW_UP: "ArrowUp";
readonly ARROW_DOWN: "ArrowDown";
readonly ARROW_LEFT: "ArrowLeft";
readonly ARROW_RIGHT: "ArrowRight";
readonly ARROW_UP_LEFT: "ArrowUp+ArrowLeft";
readonly ARROW_UP_RIGHT: "ArrowUp+ArrowRight";
readonly ARROW_DOWN_LEFT: "ArrowDown+ArrowLeft";
readonly ARROW_DOWN_RIGHT: "ArrowDown+ArrowRight";
readonly SHIFT: "Shift";
readonly CONTROL: "Control";
readonly ALT: "Alt";
readonly META: "Meta";
readonly CAPS_LOCK: "CapsLock";
readonly F1: "F1";
readonly F2: "F2";
readonly F3: "F3";
readonly F4: "F4";
readonly F5: "F5";
readonly F6: "F6";
readonly F7: "F7";
readonly F8: "F8";
readonly F9: "F9";
readonly F10: "F10";
readonly F11: "F11";
readonly F12: "F12";
readonly DIGIT_1: "1";
readonly DIGIT_2: "2";
readonly DIGIT_3: "3";
readonly DIGIT_4: "4";
readonly DIGIT_5: "5";
readonly DIGIT_6: "6";
readonly DIGIT_7: "7";
readonly DIGIT_8: "8";
readonly DIGIT_9: "9";
readonly DIGIT_0: "0";
readonly a: "a";
readonly b: "b";
readonly c: "c";
readonly d: "d";
readonly e: "e";
readonly f: "f";
readonly g: "g";
readonly h: "h";
readonly i: "i";
readonly j: "j";
readonly k: "k";
readonly l: "l";
readonly m: "m";
readonly n: "n";
readonly o: "o";
readonly p: "p";
readonly q: "q";
readonly r: "r";
readonly s: "s";
readonly t: "t";
readonly u: "u";
readonly v: "v";
readonly w: "w";
readonly x: "x";
readonly y: "y";
readonly z: "z";
readonly MINUS: "-";
readonly EQUALS: "=";
readonly BRACKET_LEFT: "[";
readonly BRACKET_RIGHT: "]";
readonly BACKSLASH: "\\";
readonly SEMICOLON: ";";
readonly QUOTE: "'";
readonly COMMA: ",";
readonly PERIOD: ".";
readonly SLASH: "/";
readonly BACKTICK: "`";
readonly NUMPAD_0: "0";
readonly NUMPAD_1: "1";
readonly NUMPAD_2: "2";
readonly NUMPAD_3: "3";
readonly NUMPAD_4: "4";
readonly NUMPAD_5: "5";
readonly NUMPAD_6: "6";
readonly NUMPAD_7: "7";
readonly NUMPAD_8: "8";
readonly NUMPAD_9: "9";
readonly NUMPAD_DECIMAL: ".";
readonly W: "w";
readonly A: "a";
readonly S: "s";
readonly D: "d";
};
/**
* Type-safe key value type derived from the Keys constant
*/
export type NormalizedKeyValue = typeof Keys[keyof typeof Keys];
/**
* Common key sequences for productivity applications
*/
export declare const CommonSequences: {
readonly SAVE_FILE: readonly ["Control", "s"];
readonly COPY: readonly ["Control", "c"];
readonly PASTE: readonly ["Control", "v"];
readonly UNDO: readonly ["Control", "z"];
readonly BRUSH_TOOL: readonly ["b"];
readonly ERASER_TOOL: readonly ["e"];
readonly PEN_TOOL: readonly ["p"];
readonly NAVIGATE_UP: readonly ["ArrowUp"];
readonly NAVIGATE_DOWN: readonly ["ArrowDown"];
readonly VIM_ESCAPE: readonly ["j", "k"];
readonly COMMAND_PALETTE: readonly ["Control", "Shift", "p"];
};
/**
* Helper function to validate if a string is a valid normalized key
*/
export declare function isValidNormalizedKey(key: string): key is NormalizedKeyValue;
/**
* Helper to get a human-readable description of a key
*/
export declare function getKeyDescription(key: string): string;
//# sourceMappingURL=keyConstants.d.ts.map