{"id":24911437,"url":"https://github.com/accessible-ui/use-key","last_synced_at":"2025-03-28T03:14:42.339Z","repository":{"id":39513700,"uuid":"277706784","full_name":"accessible-ui/use-key","owner":"accessible-ui","description":"🅰 A React hook for handling `keydown` events on specific `event.key` values. It also normalizes non-standard `event.key` values from IE to their modern equivalents.","archived":false,"fork":false,"pushed_at":"2023-01-06T10:49:10.000Z","size":2534,"stargazers_count":0,"open_issues_count":16,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-02T04:21:30.917Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/accessible-ui.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-07-07T03:27:04.000Z","updated_at":"2020-07-08T03:30:52.000Z","dependencies_parsed_at":"2023-02-05T22:17:17.788Z","dependency_job_id":null,"html_url":"https://github.com/accessible-ui/use-key","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/accessible-ui%2Fuse-key","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/accessible-ui%2Fuse-key/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/accessible-ui%2Fuse-key/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/accessible-ui%2Fuse-key/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/accessible-ui","download_url":"https://codeload.github.com/accessible-ui/use-key/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245960812,"owners_count":20700781,"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","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-02-02T04:20:08.292Z","updated_at":"2025-03-28T03:14:42.203Z","avatar_url":"https://github.com/accessible-ui.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003chr\u003e\n\u003cdiv align=\"center\"\u003e\n  \u003ch1 align=\"center\"\u003e\n    useKey()\n  \u003c/h1\u003e\n\u003c/div\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://bundlephobia.com/result?p=@accessible/use-key\"\u003e\n    \u003cimg alt=\"Bundlephobia\" src=\"https://img.shields.io/bundlephobia/minzip/@accessible/use-key?style=for-the-badge\u0026labelColor=24292e\"\u003e\n  \u003c/a\u003e\n  \u003ca aria-label=\"Code coverage report\" href=\"https://codecov.io/gh/accessible-ui/use-key\"\u003e\n    \u003cimg alt=\"Code coverage\" src=\"https://img.shields.io/codecov/c/gh/accessible-ui/use-key?style=for-the-badge\u0026labelColor=24292e\"\u003e\n  \u003c/a\u003e\n  \u003ca aria-label=\"Build status\" href=\"https://travis-ci.org/accessible-ui/use-key\"\u003e\n    \u003cimg alt=\"Build status\" src=\"https://img.shields.io/travis/accessible-ui/use-key?style=for-the-badge\u0026labelColor=24292e\"\u003e\n  \u003c/a\u003e\n  \u003ca aria-label=\"NPM version\" href=\"https://www.npmjs.com/package/@accessible/use-key\"\u003e\n    \u003cimg alt=\"NPM Version\" src=\"https://img.shields.io/npm/v/@accessible/use-key?style=for-the-badge\u0026labelColor=24292e\"\u003e\n  \u003c/a\u003e\n  \u003ca aria-label=\"License\" href=\"https://jaredlunde.mit-license.org/\"\u003e\n    \u003cimg alt=\"MIT License\" src=\"https://img.shields.io/npm/l/@accessible/use-key?style=for-the-badge\u0026labelColor=24292e\"\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n\u003cpre align=\"center\"\u003enpm i @accessible/use-key\u003c/pre\u003e\n\u003chr\u003e\n\nA React hook for handling `keydown` events on specific `event.key` values. It also\nnormalizes non-standard `event.key` values from IE to their modern equivalents.\n\n## Quick Start\n\n```jsx harmony\nimport * as React from 'react'\nimport useKey from '@accessible/use-key'\n\nconst Component = () =\u003e {\n  const ref = React.useRef(null)\n\n  // Listens to keydown events on the `ref` above\n  useKey(ref, {\n    // Logs event when the Escape key is pressed\n    Escape: console.log,\n    // Logs \"Key was pressed: Enter\" to the console when Enter is pressed\n    Enter: (event) =\u003e console.log('Key was pressed:', event.key),\n  })\n\n  // Listens to keydown events on the window\n  useKey(window, {\n    // Logs event when the Escape key is pressed\n    Escape: console.log,\n    // Logs \"Key was pressed: Enter\" to the console when Enter is pressed\n    Enter: (event) =\u003e console.log('Key was pressed:', event.key),\n  })\n\n  return \u003cdiv ref={ref} /\u003e\n}\n```\n\n## API\n\n### useKey(target, handlers)\n\n#### Arguments\n\n| Argument | Type                                                                                     | Required? | Description                                                                                                                    |\n| -------- | ---------------------------------------------------------------------------------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------ |\n| target   | \u003ccode\u003eReact.RefObject\u0026lt;T\u0026gt; \u0026#124; T \u0026#124; Window \u0026#124; Document \u0026#124; null\u003c/code\u003e | Yes       | A React ref, element, `window`, or `document` to add the key listener to                                                       |\n| handlers | `Record\u003cstring, (event?: KeyboardEvent) =\u003e any\u003e`                                         | Yes       | A mapping with keys matching the `event.key` string you want to listen on. The value for each key should be an event listener. |\n\n#### Returns `void`\n\n## LICENSE\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faccessible-ui%2Fuse-key","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faccessible-ui%2Fuse-key","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faccessible-ui%2Fuse-key/lists"}