Keyboard
Keyboard key to display symbol resolution. Platform-aware — returns macOS symbols (⌘, ⌥) on Mac and standard labels (Win, Alt) on other platforms.
Also known as: key symbols, hotkey display, shortcut symbols, keyboard symbols, key labels
When to use
- Use
getKeySymbolsto convertKeyboardEventKeyvalues to user-facing symbols. For handling keyboard shortcuts, see useKeyBinding. For displaying shortcuts in the UI, see KeysBindings and KeySymbol.
Import
tsx
import { getKeySymbols } from '@vacano/ui'getKeySymbols
Converts an array of KeyboardEventKey values to display symbols.
tsx
import { getKeySymbols } from '@vacano/ui'
// On macOS:
getKeySymbols(['Meta', 'Shift', 'K'])
// → ['⌘', '⇧', 'K']
// On Windows/Linux:
getKeySymbols(['Meta', 'Shift', 'K'])
// → ['Win', '⇧', 'K']
// No keys
getKeySymbols([]) // → []
getKeySymbols(undefined) // → []| Param | Type | Description |
|---|---|---|
keys | KeyboardEventKey[] | undefined | Optional array of keyboard keys. When undefined, returns []. |
Returns: string[] -- Display symbols. Keys without a mapping in KEY_SYMBOLS are returned as-is (e.g. letter keys like 'K' stay as 'K').
Behavior
- If
keysisundefinedor not provided, returns an empty array[]. - Detects the current OS via
getOperatingSystem(). - For each key, looks up the symbol in
KEY_SYMBOLS:- If found and OS is
'macos', returnssymbol.mac. - If found and OS is not
'macos', returnssymbol.other. - If not found in
KEY_SYMBOLS, returns the raw key string as-is.
- If found and OS is
Related
- Constants — KEY_SYMBOLS - Symbol mapping table
- useKeyBinding - Keyboard shortcut handler hook
- KeysBindings - Visual keyboard shortcut component
- KeySymbol - Single key symbol display component
- Types -
KeyboardEventKeytype definition