UNPKG

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

75 lines 2.58 kB
/** * Key Mapping Tables and Normalization Utilities * * This module contains key mapping tables and normalization functions for cross-browser * keyboard input handling. Key mapping tables are derived from HumanInput library * (Apache-2.0 licensed) with proper attribution. * * Attribution: * Key mapping tables adapted from HumanInput * Copyright (c) 2015 Dan McDougall * Licensed under the Apache License, Version 2.0 * https://github.com/liftoff/HumanInput */ declare const SYMBOL_TO_BASE_MAP: Record<string, string>; declare const NUMPAD_KEY_MAP: Record<string, string>; declare const NUMPAD_NAVIGATION_MAP: Record<string, string>; declare const KEY_CODE_NORMALIZATION_MAP: Record<string, string>; /** * Normalizes a keyboard event key value for consistent cross-browser handling * Handles shifted symbols (both numbers and punctuation) by returning their base characters * * @param event - The keyboard event to normalize * @returns Normalized key string */ export declare function normalizeKey(event: KeyboardEvent): string; /** * Gets the normalized key code for consistent identification * * @param event - The keyboard event * @returns Normalized key code */ export declare function normalizeKeyCode(event: KeyboardEvent): string; /** * Checks if a key event represents a numpad key * * @param event - The keyboard event to check * @returns True if the key is from the numpad */ export declare function isNumpadKey(event: KeyboardEvent): boolean; /** * Gets the semantic meaning of a numpad key based on NumLock state * * @param event - The keyboard event for a numpad key * @returns Object with digit and navigation values, plus active mode */ export declare function getNumpadKeyInfo(event: KeyboardEvent): { digit: string | null; navigation: string | null; activeMode: 'digit' | 'navigation'; isNumLockOn: boolean; }; /** * Checks if a key represents a modifier key * * @param key - The key string to check * @returns True if the key is a modifier key */ export declare function isModifierKey(key: string): boolean; /** * Gets comprehensive modifier state from a keyboard event * * @param event - The keyboard event * @returns Object with all modifier states */ export declare function getModifierStates(event: KeyboardEvent): { shift: boolean; ctrl: boolean; alt: boolean; meta: boolean; caps: boolean; numLock: boolean; scrollLock: boolean; }; export { SYMBOL_TO_BASE_MAP, NUMPAD_KEY_MAP, NUMPAD_NAVIGATION_MAP, KEY_CODE_NORMALIZATION_MAP, }; //# sourceMappingURL=keyMappings.d.ts.map