Skip to content
Normalization & format API Reference

validateHotkey

ts
function validateHotkey(hotkey): ValidationResult;

Defined in: validate.ts:39

Validates a hotkey and returns any warnings or errors. Each issue has a reason code, so apps can write their own messages. Issues in a sequence carry the index of their step.

Checks for:

  • Valid syntax (modifier+...+key format)
  • Known modifiers
  • A key that isn't a modifier
  • Known keys

Parameters

hotkey

ValidatableHotkey

The hotkey string to validate

Returns

ValidationResult

A ValidationResult with validity status, warnings, and errors

Example

ts
validateHotkey('Mod+S')
// { valid: true, warnings: [], errors: [] }

validateHotkey('')
// { valid: false, warnings: [], errors: [{ reason: 'empty' }] }

validateHotkey(['G', 'Foo+H'])
// { valid: false, warnings: [], errors: [{ reason: 'unknown-modifier', part: 'Foo', step: 1 }] }