--- title: Sensible Defaults and Keyboard Layouts id: sensible-defaults description: How TanStack Hotkeys handles platforms, keyboard layouts, text inputs, and browser behavior by default, and how to change each default. --- Register `Mod+S` with no options and it behaves the way users expect: Command+S on macOS, Control+S elsewhere, the browser's Save dialog stays closed, it still works while the user is typing in a text field, and it works on any keyboard layout. TanStack Hotkeys chooses its defaults so the common case needs no configuration. This guide describes each default, why it was chosen, and how to change it. ## At a glance | Behavior | Default | Change it with | | --- | --- | --- | | `Mod` modifier | Command on macOS, Control on Windows and Linux | `platform` | | Key identity | The character the key types (`event.key`), with a fallback to the key's position | `[KeyS]` physical bindings | | Modifiers | Must match exactly | List every modifier in the binding | | Typing in inputs | Single keys and `Shift`/`Alt` chords are ignored; `Control`/`Meta` chords and `Escape` fire | `ignoreInputs` | | Browser behavior | Prevented, and the event stops propagating | `preventDefault`, `stopPropagation` | | Hotkeys that can't fire | The browser acts on the key | `preventDefault: 'always'` | | When a chord fires | On keydown, and again on each automatic repeat while held | `eventType`, `requireReset` | | Where listeners attach | `document` | `target` | | When hotkeys run | After the keyboard handlers of widgets inside the target (bubble phase) | `capture` | | Keys another listener prevented | Hotkeys still fire | `ignoreDefaultPrevented` | | Time between sequence steps | 1 second | `timeout` | | Duplicate registrations | Allowed, with a console warning in development | `conflictBehavior` | | Recording | Records key positions; Escape cancels | `recordBy`, recorder options | | Display | Symbols on macOS (`⇧ ⌘ S`), text elsewhere (`Ctrl+Shift+S`) | `formatForDisplay` options | ## `Mod` follows the platform `Mod` is the platform's primary shortcut modifier: Command (`Meta`) on macOS and Control on Windows and Linux. Write `Mod+S` once and each user gets the save shortcut their operating system has trained them to use. The platform is detected from `navigator`. During server rendering, where there is no `navigator`, it is `linux`. Hotkeys are stored in a canonical form, so equivalent spellings are the same binding. On Windows and Linux, `Control+S` and `ctrl+s` are stored as `Mod+S`. On macOS, `Control+S` remains `Control+S`, because Control is not the primary modifier there. This is why two spellings conflict on one platform and not on another. Pass `platform: 'mac' | 'windows' | 'linux'` to override detection, for example in tests or to preview another platform's shortcuts. ## Keys match the character the user types A logical binding such as `Mod+S` or `?` matches `event.key`, the character the key produces on the active keyboard layout. A user on Dvorak, Colemak, or AZERTY presses the key labeled S to trigger `Mod+S`, wherever that key sits on their keyboard. Matching the key's position (`event.code`) instead would make `Mod+Z` fire on the AZERTY key labeled W, and on Dvorak would turn the key labeled X into a different shortcut. `event.key` is not always useful, so the matcher falls back to the key's conventional position when the character cannot identify the shortcut: - **Non-Latin layouts.** On a Russian layout, the S position types `ы`. `Mod+S` still matches there, so shortcuts work without switching layouts. - **macOS Option.** Option changes the character, so Option+S types `ß`. `Alt+S` still matches. - **Dead keys and the digit row.** A dead key reports `Dead`, and AZERTY's digit row types `&` and `é` for `1` and `2`. The key's position resolves the shortcut, so `Mod+1` works on AZERTY. - **Symbols typed with Shift.** Shift+1 types `!` on a US layout, and `Shift+1` still matches. Otherwise, the character the key reports wins, wherever the key sits: - ASCII letters never fall back, and ASCII symbols fall back only on the digit row or with Shift. On AZERTY, the key in the US `/` position types `+`, so Cmd++ zooms the page instead of firing `Mod+/`. On Dvorak, the key that types `'` does not fire `Q`. - Latin letters such as `ü`, `ö`, and `ø` match only themselves when typed on their own. With Control or Command held on a punctuation key they fall back, so German Cmd+ü still fires `Mod+[` (German types `[` with Option). - Named keys never fall back. With NumLock off, the numpad's 1 key reports `End`, so it fires `End` and not `1`. When one key press could match several registrations on the same target, an exact match takes priority over a fallback. A symbol that needs Shift on some layouts, such as `/` on German QWERTZ (Shift+7), matches when typed on its own. With Command held, macOS browsers report the unshifted character instead (`7`), so `Mod+/` can't match there. Register the per-layout combination as well, such as `Mod+Shift+7`. Letters match without regard to case: `S` and `s` are the same binding. ### Match a key's position instead When a shortcut should follow a position rather than a character, such as `W`/`A`/`S`/`D` movement in a game, use a physical binding. Physical bindings match `event.code` exactly and ignore the layout: | Binding | Matches | | --- | --- | | `Mod+S` or `{ key: 'S', mod: true }` | The character S (`event.key`), with the fallbacks above | | `Mod+[KeyS]` or `{ code: 'KeyS', mod: true }` | The key in the S position on a US layout (`event.code`) | | `Enter` | Either Enter key, including the numpad's | | `[Enter]` or `[NumpadEnter]` | Only that Enter key | On a layout where the `KeyQ` position types `a`, `A` follows the character and `[KeyQ]` follows the position. - In strings, every physical code goes in brackets, including codes that share a name with a logical key, such as `[Enter]` and `[F13]`. Codes are type-checked and autocomplete in your editor. - In objects, use the `code` field for a physical binding and `key` for a logical one. A binding has one or the other, never both, and `key` never takes brackets. - In a chord's callback, `context.parsedChord.code` is set only for physical bindings. The same goes for each step in a sequence's `context.parsedSequence`. Check `code !== undefined` before reading it. - `formatForDisplay` labels physical bindings without brackets, so `Mod+[KeyS]` displays as `⌘ S` on macOS. The stored binding keeps its brackets. The [hotkey recorder](#recording-captures-what-the-user-pressed) records positions by default, so recorded hotkeys are physical bindings. ## Modifiers must match exactly `Mod+S` does not fire for `Mod+Shift+S`, and `K` does not fire for `Shift+K`. Exact matching lets `Mod+Z` (undo) and `Mod+Shift+Z` (redo) coexist without one swallowing the other. The exception is Shift that is needed to type a symbol. On a US layout, `?` is typed with Shift+/, so `?` matches without listing `Shift`. This applies to printable symbols, not letters, so `K` and `Shift+K` remain different bindings. Two kinds of key events never match ordinary shortcuts: - **AltGr.** On Windows and Linux, AltGr types characters such as `@` and `€` on many layouts. A character it types matches a binding for that character, but never a `Control+Alt` shortcut, so typing an email address does not run a command. When AltGr+key types nothing new, such as AltGr+Home, or AltGr+F on a layout with nothing on that key, it does not fire `Home` or `F`. Windows reports AltGr as Control+Alt, so there it fires `Control+Alt` shortcuts instead: AltGr+Home triggers `Control+Alt+Home`, as in native Windows apps. - **IME composition.** While the user composes text with an input method editor, such as for Japanese, Chinese, or Korean, no hotkey fires, because the editor uses those keys: Enter commits the text, Escape cancels it, and the arrow keys pick a candidate. This includes the Enter that Safari sends right after composition ends. ## Typing in inputs does not trigger shortcuts A hotkey bound to `K` should not fire while the user types "okay" into a text field. By default, `ignoreInputs` is `'auto'`, which chooses from the hotkey itself: | Hotkey | Default | Reason | | --- | --- | --- | | `K`, `Shift+K`, `Alt+K`, `?` | Ignored in inputs | These keys type text | | `Mod+S`, `Control+K`, `Meta+Enter` | Fire in inputs | Control and Meta chords don't type text, and users expect save and similar commands to work from a field | | `Escape` | Fires in inputs | Users expect Escape to close a dialog even when a field inside it has focus | For a sequence, the first step decides, so `['G', 'G']` is ignored in inputs. These count as inputs, including inside open shadow roots: - Text-entry inputs, such as `text`, `search`, `email`, `number`, and the date and time types, unless they are read-only - Textareas that aren't read-only, and selects - `contenteditable` elements, and elements with `role="textbox"` or `role="searchbox"` - Custom elements that may hide a text field: a host whose focus is inside a closed shadow root, and a form-associated custom element without a `role` attribute Checkbox, radio, range, color, file, and button-type inputs are not text fields, so `K` still fires while one has focus. They keep only the keys they use (see [Focused controls keep their own keys](#focused-controls-keep-their-own-keys)). A form-associated custom element that isn't a text field can set a `role` attribute, such as `role="checkbox"`, to get the same treatment. A hotkey whose `target` is the input itself always receives that input's events. Set `ignoreInputs: true` or `false` to choose explicitly. For example, set `ignoreInputs: false` on an `Enter` hotkey that submits a form, so it works while focus is in the form's text fields. ## Focused controls keep their own keys Buttons, links, and ARIA widgets also use keys for themselves. A hotkey bound to `Enter` should not stop a focused button from clicking, and a hotkey bound to `ArrowDown` should not also run while the user moves through an open menu. When `ignoreInputs` is on, a hotkey skips these keys while such a control has focus: | Focused control | Keys it keeps | | --- | --- | | `