{"id":30292515,"url":"https://github.com/bholmesdev/keymatch","last_synced_at":"2025-08-17T00:34:25.589Z","repository":{"id":306927053,"uuid":"1027708440","full_name":"bholmesdev/keymatch","owner":"bholmesdev","description":"Utility for matching browser keyboard events across platforms","archived":false,"fork":false,"pushed_at":"2025-07-28T12:28:40.000Z","size":23,"stargazers_count":10,"open_issues_count":1,"forks_count":1,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-07-28T14:30:11.157Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bholmesdev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-07-28T12:15:29.000Z","updated_at":"2025-07-28T14:03:22.000Z","dependencies_parsed_at":"2025-07-28T14:30:51.979Z","dependency_job_id":"fc968b64-b106-4c35-b741-1c3db73292f0","html_url":"https://github.com/bholmesdev/keymatch","commit_stats":null,"previous_names":["hubblenote/keymatch"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/bholmesdev/keymatch","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bholmesdev%2Fkeymatch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bholmesdev%2Fkeymatch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bholmesdev%2Fkeymatch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bholmesdev%2Fkeymatch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bholmesdev","download_url":"https://codeload.github.com/bholmesdev/keymatch/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bholmesdev%2Fkeymatch/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270791280,"owners_count":24645781,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-16T02:00:11.002Z","response_time":91,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-08-17T00:34:23.272Z","updated_at":"2025-08-17T00:34:25.578Z","avatar_url":"https://github.com/bholmesdev.png","language":"TypeScript","readme":"# keymatch\n\nA utility for matching keyboard events against Electron accelerator strings.\n\n## Installation\n\n```bash\nnpm install keymatch\n# or\npnpm add keymatch\n# or\nyarn add keymatch\n```\n\n## Usage\n\n### Adapting to Platform-Specific Modifiers\n\nUse \"CmdOrCtrl\" to adapt your modifier key to \"Command\" (MacOS) or \"Ctrl\" depending on the platform. This can be combined with other modifiers like \"Alt\" or \"Shift\" using `+`: \n\n```typescript\nimport { keymatch } from 'keymatch';\n\ndocument.addEventListener('keydown', (event) =\u003e {\n  if (keymatch(event, 'CmdOrCtrl+Shift+N')) {\n    event.preventDefault();\n    createNewFile();\n  }\n});\n```\n\n### Handling Single Letter Matches\n\nYou can also handle single-letter matches that explicitly *don't* have modifiers. For example, this matches when \"A\" is pressed, but not when \"Cmd+A\" is pressed:\n\n```typescript\ndocument.addEventListener('keydown', (event) =\u003e {\n  if (keymatch(event, 'A')) {\n    event.preventDefault();\n    selectAll();\n  }\n});\n```\n\n### Using Platform-Specific matches\n\nYou can also create platform-specific matches by combining with the isMac() utility. This example uses `Cmd` for a MacOS shortcut, and `Ctrl+Shift` for other platforms:\n\n```typescript\nimport { keymatch, isMac } from 'keymatch';\n\ndocument.addEventListener('keydown', (event) =\u003e {\n  if (keymatch(event, isMac() ? 'Cmd+K' : 'Ctrl+Shift+K')) {\n    event.preventDefault();\n    openCommandPalette();\n  }\n});\n```\n\n### Handling Arrow Keys\n\nkeymatch also supports Electron accelerator shorthands, like \"Up\" to represent \"ArrowUp\":\n\n```typescript\ndocument.addEventListener('keydown', (event) =\u003e {\n  if (keymatch(event, 'CmdOrCtrl+Up')) {\n    event.preventDefault();\n    moveSelectionToTop();\n  }\n});\n```\n\n## Supported Accelerator Formats\n\nThe library supports [Electron-style accelerator strings](https://www.electronjs.org/docs/latest/api/accelerator):\n\n### Modifiers\n- `Cmd` or `Command` - Maps to metaKey (⌘ on Mac)\n- `Ctrl` or `Control` - Maps to ctrlKey \n- `CmdOrCtrl` or `CommandOrControl` - Uses Cmd on MacOS, Ctrl on other platforms\n- `Alt` - Uses Option on MacOS, Alt on other platforms\n- `Shift` - Maps to shiftKey\n- `Meta` or `Super` - Maps to metaKey\n- `Option` - Maps to Option on MacOS. Note this modifier will only match on MacOS! Use `Alt` for a platform-agnostic match.\n\n### Keys\nAny key that can be captured by a KeyboardEvent, including:\n- Letter keys: `A`, `B`, `C`, etc.\n- Number keys: `1`, `2`, `3`, etc.\n- Function keys: `F1`, `F2`, `F3`, etc.\n- Special keys: `Space`, `Enter`, `Escape`, `Tab`, `Delete`, etc.\n- Arrow keys: `Up`, `Down`, `Left`, `Right` (also accepts `ArrowUp`, `ArrowDown`, etc.)\n\n## API\n\n### `keymatch(event: KeyboardEvent, accelerator: string): boolean`\n\nChecks if a KeyboardEvent matches the given accelerator string.\n\n**Parameters:**\n- `event` - The web-standard KeyboardEvent to test\n- `accelerator` - The Electron-style accelerator string\n\n**Returns:**\n- `boolean` - True if the event matches the accelerator\n\n### `isMac(): boolean`\n\nUtility function to detect if the current platform is MacOS.\n\n**Returns:**\n- `boolean` - True if running on MacOS, false otherwise\n\n## License\n\nMIT\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbholmesdev%2Fkeymatch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbholmesdev%2Fkeymatch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbholmesdev%2Fkeymatch/lists"}