Defined in: types.ts:99
Registrations and reactive state owned by one Alpine component.
createAppHotkeyList: () => AlpineHotkeyState<RegisteredAppHotkeyListItem[]>;Defined in: types.ts:273
Read every app hotkey with its live status through .value.
AlpineHotkeyState<RegisteredAppHotkeyListItem[]>
createAppHotkeys: () => AlpineHotkeyState<Readonly<Record<string, AppHotkey<string, HotkeyChord | HotkeySequence | null>>>>;Defined in: types.ts:271
Read the effective app hotkeys from provideAppHotkeys through .value.
AlpineHotkeyState<Readonly<Record<string, AppHotkey<string, HotkeyChord | HotkeySequence | null>>>>
createCustomHotkeys: () => AlpineCustomHotkeys;Defined in: types.ts:277
Read and change the user's custom hotkeys.
createFormatForAria: () => (hotkey, options) => string | undefined;Defined in: types.ts:237
Returns formatForAria with the scope's platform as the default, or the detected platform without one. Use its value for aria-keyshortcuts, so screen readers announce the shortcut. It returns undefined for a multi-step sequence, no hotkey, or a hotkey that can't fire right now (one that is disabled, in a suspended scope, a suspended character key, or not registered), so x-bind omits the attribute. An explicit platform option wins.
Physical bindings such as [KeyQ] name the key the user presses in Chromium browsers, once the keyboard layout has loaded, the same way as createFormatForDisplay. A layoutMap passed to the returned function wins.
Create it once, then call the returned function anywhere.
(hotkey, options?): string | undefined;Formats a hotkey for an aria-keyshortcuts attribute so screen readers can announce the shortcut. Mod+K becomes Meta+K on macOS and Control+K elsewhere.
Modifiers use the ARIA names (Control, Alt, Shift, Meta) and come before the key. Keys use KeyboardEvent.key values, such as K, /, Escape, or ArrowUp, with Space for the space bar and Plus for the plus key. A physical binding names the key at that position, so [KeyQ] becomes Q, or the key from layoutMap such as A on a French AZERTY keyboard. Logical punctuation stays as written, so '?' stays ? even where it takes Shift to type.
Returns undefined when the hotkey has no ARIA form, so the attribute is omitted. This applies to empty or null hotkeys, multi-step sequences, standalone modifiers, and physical codes with no key value such as [NumpadMemoryAdd]. A one-step sequence formats like its chord.
For a control with two shortcuts, join both formatted values with a space. In a server-rendered app, use your adapter's formatter or pass platform. Without a platform option, formatForAria uses 'linux' on the server, like formatForDisplay.
DisplayHotkey | null | undefined
A hotkey string, raw object, parsed chord, or nothing
FormatAriaOptions = {}
The platform and keyboard layout
string | undefined
The attribute value, or undefined when there is none
formatForAria('Mod+K', { platform: 'mac' }) // 'Meta+K'
formatForAria('Mod+Shift+P', { platform: 'windows' }) // 'Control+Shift+P'
formatForAria('Shift+Space') // 'Shift+Space'
formatForAria(['G', 'H']) // undefinedAlpine.data('searchButton', () => {
const hotkeys = createHotkeysScope()
const formatForAria = hotkeys.createFormatForAria()
return {
get shortcut() {
return formatForAria('Mod+K')
},
destroy() {
hotkeys.destroy()
},
}
})<button x-data="searchButton" :aria-keyshortcuts="shortcut">Search</button>createFormatForDisplay: () => {
(hotkey, options): string[][];
(hotkey, options): string[];
(hotkey, options?): string;
(hotkey, options): string | string[] | string[][];
};Defined in: types.ts:199
Returns formatForDisplay with the scope's platform as the default, or the detected platform without one. A platform passed to the returned function wins.
Physical bindings such as [KeyQ] are labeled with the character the key types for this user in Chromium browsers, once the keyboard layout has loaded. A getter or an x-text expression that calls the function runs again when the layout arrives. See createKeyboardLayout. A layoutMap passed to the returned function wins. To never ask the browser for the layout, set keyboardLayout: false in the scope's default options. Firefox and Safari report no layout, so labels there keep the key's US character.
Create it once, then call the returned function anywhere.
(hotkey, options): string[][];Formats a hotkey for display in a user interface.
In a server-rendered app, format labels with your adapter's formatter, such as useFormatForDisplay, or pass platform. Called directly, formatForDisplay never reads a provider's platform. Without a platform option, it renders Linux labels on the server, so Mac users get a different label after hydration.
On macOS, uses symbols (⇧⌘S) in Control, Option, Shift, Command order. Display ordering does not change the normalized hotkey used for registration. On Windows/Linux, uses text (Ctrl+Shift+S) with + separators. The separator can be customized with separatorToken. Physical codes use conventional display labels: [KeyS] becomes S and [Digit2] becomes 2. Keys with no US key use their keycap legends: [IntlBackslash] and [IntlRo] become \ and [IntlYen] becomes ¥. These labels do not infer the active keyboard layout or change matching. Supply a resolved layoutMap for layout-aware labels; keyLabels overrides both layout entries and fallback labels. Sequence steps are formatted individually and joined with sequenceSeparator (a space by default).
A key reported by a KeyboardEvent, such as a held key from KeyStateTracker, can be outside the key types: pass it as { key }.
readonly DisplayHotkeyChord[]
A logical or physical hotkey string, raw object, ParsedHotkeyChord, or sequence
FormatDisplayOptions & object
Formatting options
string[][]
Display text, or individual key labels when parts is true (one array per step for sequences)
formatForDisplay('Mod+Shift+S', { platform: 'mac' })
// Returns: '⇧ ⌘ S' (symbols separated by spaces on macOS)
formatForDisplay('Mod+Shift+S', { platform: 'windows' })
// Returns: 'Ctrl+Shift+S'
formatForDisplay('Escape')
// Returns: 'Esc' (on all platforms)
formatForDisplay('Shift', { platform: 'mac' })
// Returns: '⇧'
formatForDisplay({ key: heldKey })
// A key from a KeyboardEvent, such as a held key
formatForDisplay(['G', 'H'])
// Returns: 'G H'(hotkey, options): string[];Formats a hotkey for display in a user interface.
In a server-rendered app, format labels with your adapter's formatter, such as useFormatForDisplay, or pass platform. Called directly, formatForDisplay never reads a provider's platform. Without a platform option, it renders Linux labels on the server, so Mac users get a different label after hydration.
On macOS, uses symbols (⇧⌘S) in Control, Option, Shift, Command order. Display ordering does not change the normalized hotkey used for registration. On Windows/Linux, uses text (Ctrl+Shift+S) with + separators. The separator can be customized with separatorToken. Physical codes use conventional display labels: [KeyS] becomes S and [Digit2] becomes 2. Keys with no US key use their keycap legends: [IntlBackslash] and [IntlRo] become \ and [IntlYen] becomes ¥. These labels do not infer the active keyboard layout or change matching. Supply a resolved layoutMap for layout-aware labels; keyLabels overrides both layout entries and fallback labels. Sequence steps are formatted individually and joined with sequenceSeparator (a space by default).
A key reported by a KeyboardEvent, such as a held key from KeyStateTracker, can be outside the key types: pass it as { key }.
DisplayHotkeyChord
A logical or physical hotkey string, raw object, ParsedHotkeyChord, or sequence
FormatDisplayOptions & object
Formatting options
string[]
Display text, or individual key labels when parts is true (one array per step for sequences)
formatForDisplay('Mod+Shift+S', { platform: 'mac' })
// Returns: '⇧ ⌘ S' (symbols separated by spaces on macOS)
formatForDisplay('Mod+Shift+S', { platform: 'windows' })
// Returns: 'Ctrl+Shift+S'
formatForDisplay('Escape')
// Returns: 'Esc' (on all platforms)
formatForDisplay('Shift', { platform: 'mac' })
// Returns: '⇧'
formatForDisplay({ key: heldKey })
// A key from a KeyboardEvent, such as a held key
formatForDisplay(['G', 'H'])
// Returns: 'G H'(hotkey, options?): string;Formats a hotkey for display in a user interface.
In a server-rendered app, format labels with your adapter's formatter, such as useFormatForDisplay, or pass platform. Called directly, formatForDisplay never reads a provider's platform. Without a platform option, it renders Linux labels on the server, so Mac users get a different label after hydration.
On macOS, uses symbols (⇧⌘S) in Control, Option, Shift, Command order. Display ordering does not change the normalized hotkey used for registration. On Windows/Linux, uses text (Ctrl+Shift+S) with + separators. The separator can be customized with separatorToken. Physical codes use conventional display labels: [KeyS] becomes S and [Digit2] becomes 2. Keys with no US key use their keycap legends: [IntlBackslash] and [IntlRo] become \ and [IntlYen] becomes ¥. These labels do not infer the active keyboard layout or change matching. Supply a resolved layoutMap for layout-aware labels; keyLabels overrides both layout entries and fallback labels. Sequence steps are formatted individually and joined with sequenceSeparator (a space by default).
A key reported by a KeyboardEvent, such as a held key from KeyStateTracker, can be outside the key types: pass it as { key }.
DisplayHotkey
A logical or physical hotkey string, raw object, ParsedHotkeyChord, or sequence
FormatDisplayOptions & object
Formatting options
string
Display text, or individual key labels when parts is true (one array per step for sequences)
formatForDisplay('Mod+Shift+S', { platform: 'mac' })
// Returns: '⇧ ⌘ S' (symbols separated by spaces on macOS)
formatForDisplay('Mod+Shift+S', { platform: 'windows' })
// Returns: 'Ctrl+Shift+S'
formatForDisplay('Escape')
// Returns: 'Esc' (on all platforms)
formatForDisplay('Shift', { platform: 'mac' })
// Returns: '⇧'
formatForDisplay({ key: heldKey })
// A key from a KeyboardEvent, such as a held key
formatForDisplay(['G', 'H'])
// Returns: 'G H'(hotkey, options): string | string[] | string[][];Formats a hotkey for display in a user interface.
In a server-rendered app, format labels with your adapter's formatter, such as useFormatForDisplay, or pass platform. Called directly, formatForDisplay never reads a provider's platform. Without a platform option, it renders Linux labels on the server, so Mac users get a different label after hydration.
On macOS, uses symbols (⇧⌘S) in Control, Option, Shift, Command order. Display ordering does not change the normalized hotkey used for registration. On Windows/Linux, uses text (Ctrl+Shift+S) with + separators. The separator can be customized with separatorToken. Physical codes use conventional display labels: [KeyS] becomes S and [Digit2] becomes 2. Keys with no US key use their keycap legends: [IntlBackslash] and [IntlRo] become \ and [IntlYen] becomes ¥. These labels do not infer the active keyboard layout or change matching. Supply a resolved layoutMap for layout-aware labels; keyLabels overrides both layout entries and fallback labels. Sequence steps are formatted individually and joined with sequenceSeparator (a space by default).
A key reported by a KeyboardEvent, such as a held key from KeyStateTracker, can be outside the key types: pass it as { key }.
DisplayHotkey
A logical or physical hotkey string, raw object, ParsedHotkeyChord, or sequence
FormatDisplayOptions
Formatting options
string | string[] | string[][]
Display text, or individual key labels when parts is true (one array per step for sequences)
formatForDisplay('Mod+Shift+S', { platform: 'mac' })
// Returns: '⇧ ⌘ S' (symbols separated by spaces on macOS)
formatForDisplay('Mod+Shift+S', { platform: 'windows' })
// Returns: 'Ctrl+Shift+S'
formatForDisplay('Escape')
// Returns: 'Esc' (on all platforms)
formatForDisplay('Shift', { platform: 'mac' })
// Returns: '⇧'
formatForDisplay({ key: heldKey })
// A key from a KeyboardEvent, such as a held key
formatForDisplay(['G', 'H'])
// Returns: 'G H'Alpine.data('saveButton', () => {
const hotkeys = createHotkeysScope()
const formatForDisplay = hotkeys.createFormatForDisplay()
return {
get label() {
return formatForDisplay('Mod+S')
},
destroy() {
hotkeys.destroy()
},
}
})createHeldKeyCodes: () => AlpineHotkeyState<Record<string, string>>;Defined in: types.ts:114
Read the mapping of held logical names to physical codes through .value.
AlpineHotkeyState<Record<string, string>>
createHeldKeys: () => AlpineHotkeyState<string[]>;Defined in: types.ts:112
Read held logical key names through .value.
AlpineHotkeyState<string[]>
createHotkey: AlpineCreateHotkey;Defined in: types.ts:105
Register one hotkey: a chord such as 'Mod+S', a sequence such as ['G', 'G'], or an app hotkey. Getters track changing hotkeys and options. undefined, null, or '' registers nothing, for an optional shortcut.
createHotkeyHint: (hotkey, options?) => AlpineHotkeyState<boolean>;Defined in: types.ts:159
Read whether held modifiers reveal a hotkey through .value. No hotkey (undefined, null, or '') is never visible.
MaybeGetter< | RegisterableHotkey | AppHotkey<string, HotkeyChord | HotkeySequence | null> | null | undefined>
MaybeGetter<HeldModifierOptions>
AlpineHotkeyState<boolean>
createHotkeyRegistrations: () => HotkeyRegistrationsResult;Defined in: types.ts:164
Read live registrations, including disabled entries.
HotkeyRegistrationsResult
createHotkeys: (definitions, options?) => void;Defined in: types.ts:107
Reconcile a list of hotkeys. Definition options override common options.
MaybeGetter<readonly AlpineHotkeyDefinition[]>
MaybeGetter<AlpineHotkeyCommonOptions>
void
createHotkeyScopesState: () => AlpineHotkeyState<HotkeyScopesState>;Defined in: types.ts:166
Read the active, exclusive, allowed, and suspended scopes through .value.
AlpineHotkeyState<HotkeyScopesState>
createKeyboardLayout: () => AlpineHotkeyState<KeyboardLayoutMap | null>;Defined in: types.ts:269
Read the browser's keyboard layout through .value, or null until it loads and in browsers that don't report one. The layout maps each physical code to the character it types, such as KeyQ to a on a French AZERTY keyboard. Only Chromium browsers report one.
Creating it is what loads the layout. The layout is read again when the window regains focus, until the scope is destroyed. createFormatForDisplay uses it, so you only need it for labels you draw yourself.
To never ask the browser for the layout, set keyboardLayout: false in the scope's default options. .value is then null.
AlpineHotkeyState<KeyboardLayoutMap | null>
Alpine.data('moveKeys', () => {
const hotkeys = createHotkeysScope()
const layout = hotkeys.createKeyboardLayout()
return {
label(code: string) {
return (layout.value?.get(code) ?? code).toUpperCase()
},
destroy() {
hotkeys.destroy()
},
}
})createKeyHold: (key) => AlpineHotkeyState<boolean>;Defined in: types.ts:116
Read whether a key is held through .value.
MaybeGetter<IndividualKey>
AlpineHotkeyState<boolean>
createKeyLockState: (key) => AlpineHotkeyState<boolean | null>;Defined in: types.ts:152
Read whether a lock key, such as Caps Lock, is on through .value: true when the lock is on, false when it is off, or null. Pass 'CapsLock', 'NumLock', or 'ScrollLock', or a getter.
Lock keys toggle instead of being held, so this reads the lock state that the browser reports on key and mouse events. .value is null until the user presses a key, clicks, or moves the mouse, after the window loses focus or the page is hidden, and always for Num Lock and Scroll Lock on macOS and iOS.
MaybeGetter<LockKey>
AlpineHotkeyState<boolean | null>
Alpine.data('passwordField', () => {
const hotkeys = createHotkeysScope()
const capsLock = hotkeys.createKeyLockState('CapsLock')
return {
get capsLockOn() {
return capsLock.value === true
},
destroy() {
hotkeys.destroy()
},
}
})<label x-data="passwordField">
Password
<input type="password" />
<span x-show="capsLockOn" role="status">Caps Lock is on</span>
</label>destroy: () => void;Defined in: types.ts:279
Release every registration, subscription, effect, and recorder. Idempotent.
void