Keyboard behavior for web-built desktop apps — the platform modifier (⌘ on macOS, Ctrl elsewhere) instead of accepting both, shortcut labels per platform, Escape and Enter in dialogs, standard shortcuts (⌘, ⌘W ⌘N ⌘Q and Ctrl equivalents), arrow-key list navigation with roving tabindex, shortcuts that fire while typing, and global shortcuts that collide with menus or the OS. Use when adding shortcuts, a command palette, keyboard navigation, or when shortcuts behave or display wrong on one plat...
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Desktop Keyboard?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/agmmnn-desktop-keyboard)
---
name: desktop-keyboard
description: Keyboard behavior for web-built desktop apps — the platform modifier (⌘ on macOS, Ctrl elsewhere) instead of accepting both, shortcut labels per platform, Escape and Enter in dialogs, standard shortcuts (⌘, ⌘W ⌘N ⌘Q and Ctrl equivalents), arrow-key list navigation with roving tabindex, shortcuts that fire while typing, and global shortcuts that collide with menus or the OS. Use when adding shortcuts, a command palette, keyboard navigation, or when shortcuts behave or display wrong on one platform.
---
# Desktop Keyboard
## Initial Response
When this skill is first invoked without a specific question, respond only with:
> Ready to work on keyboard behavior. Tell me which shortcuts or which screen.
Desktop users live on the keyboard. A web app treats it as an afterthought: shortcuts that work on one platform, labels that say Ctrl on a Mac, lists you can only click.
## Hard Rules
1. **One modifier per platform.** ⌘ on macOS, Ctrl on Windows and Linux. Accepting both makes Ctrl+C-style combos fire on macOS where Ctrl means something else (Emacs bindings in text fields, Ctrl-click).
2. **Menu accelerators are the source of truth** when the app has a native menu (`native-menus`). Don't register the same shortcut twice.
3. **Never steal OS or text-editing shortcuts.** ⌘Q/⌘H/⌘M on macOS, Alt+F4/Win+… on Windows, and every text-editing shortcut inside inputs.
4. **Get the platform from the shell**, not the user agent (`platform()` from `@tauri-apps/plugin-os` in Tauri; `process.platform` exposed through the preload script in Electron).
## The Symptom Table
| Problem | Solution | Rule |
| --- | --- | --- |
| Shortcut fires on both ⌘ and Ctrl on macOS | Platform modifier only | DK-01 |
| "Ctrl+K" shown on a Mac | Labels per platform | DK-02 |
| Escape doesn't close, Enter doesn't submit | Dialog keyboard contract | DK-03 |
| ⌘, / ⌘W / ⌘N do nothing | Standard shortcuts | DK-04 |
| Arrow keys don't move through a list | Roving tabindex | DK-05 |
| Typing "d" in a field triggers an action | Skip editable targets | DK-06 |
| Global shortcut steals a menu or OS shortcut | Check collisions | DK-07 |
## The Fixes
### DK-01 Platform modifier
```ts
const isMac = (await platform()) === "macos" // @tauri-apps/plugin-os
export const mod = (e: KeyboardEvent) => (isMac ? e.metaKey && !e.ctrlKey : e.ctrlKey && !e.metaKey)
```
### DK-02 Labels per platform
```ts
const label = (keys: string) => isMac
? keys.replace("Mod", "⌘").replace("Shift", "⇧").replace("Alt", "⌥").replace(/\+/g, "")
: keys.replace("Mod", "Ctrl")
// label("Mod+Shift+K") → "⌘⇧K" on macOS, "Ctrl+Shift+K" elsewhere
```
macOS symbol order: ⌃ ⌥ ⇧ ⌘ then the key. Use `<kbd>` with `tabular-nums` so labels line up.
### DK-03 Dialog keyboard contract
Escape closes dialogs, popovers and menus (and cancels a drag). Enter activates the default button, which is visibly marked. Focus moves into a dialog when it opens and returns to the trigger when it closes. Destructive confirmations do not make the destructive button the Enter default.
### DK-04 Standard shortcuts
| Action | macOS | Windows / Linux |
| --- | --- | --- |
| Settings | ⌘, | Ctrl+, (or none; Settings in a menu) |
| New | ⌘N | Ctrl+N |
| Close window/tab | ⌘W | Ctrl+W |
| Quit | ⌘Q (from the app menu) | Alt+F4 (OS) |
| Find | ⌘F | Ctrl+F |
| Undo / Redo | ⌘Z / ⇧⌘Z | Ctrl+Z / Ctrl+Y |
Implement the ones the app has a meaning for; don't invent meanings.
### DK-05 Keyboard-navigable lists
Lists, trees and grids are one tab stop; arrow keys move within. Up/Down, Home/End, type-ahead to the first matching item, Space/Enter to activate, Shift+arrows to extend selection where multi-select exists. Use roving `tabindex` (`0` on the active item, `-1` on others) or `aria-activedescendant`.
### DK-06 Skip editable targets
```ts
function isEditable(t: EventTarget | null) {
return t instanceof HTMLElement && (t.isContentEditable || /^(INPUT|TEXTAREA|SELECT)$/.test(t.tagName))
}
window.addEventListener("keydown", (e) => {
if (isEditable(e.target) && !mod(e)) return // plain keys belong to the field
// …
})
```
### DK-07 Global shortcuts don't collide
Global shortcuts (`tauri-plugin-global-shortcut`) work while the app is in the background, so they compete with every other app. Use them only for features that need them (a launcher, push-to-talk), make them configurable, and handle registration failure (another app owns the combo).
## Never Ship
| Never | Instead |
| --- | --- |
| `e.metaKey \|\| e.ctrlKey` | The platform modifier |
| "Ctrl" in labels on macOS | Symbols per platform |
| Plain-key shortcuts that fire in inputs | Editable-target check |
| Lists only reachable by mouse | Arrow-key navigation |
| A hard-coded global shortcut | Configurable, failure handled |
## Output
| Rule | File | Change | Verified |
| --- | --- | --- | --- |
Keyboard behavior can mostly be verified from code; list anything that depends on OS shortcuts.