{"id":13422383,"url":"https://github.com/pranesh239/use-key-capture","last_synced_at":"2025-03-15T12:30:40.661Z","repository":{"id":57388155,"uuid":"232149531","full_name":"pranesh239/use-key-capture","owner":"pranesh239","description":"Makes listening to key press event easy. ","archived":false,"fork":false,"pushed_at":"2024-04-23T02:07:42.000Z","size":4338,"stargazers_count":24,"open_issues_count":2,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-04-23T05:45:01.519Z","etag":null,"topics":["custom-hook","hacktoberfest","keyboard-events","react","react-hooks"],"latest_commit_sha":null,"homepage":"https://use-key-capture.netlify.com/","language":"JavaScript","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/pranesh239.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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}},"created_at":"2020-01-06T17:20:43.000Z","updated_at":"2024-07-31T01:44:05.563Z","dependencies_parsed_at":"2024-07-31T01:43:41.734Z","dependency_job_id":"b0e2f0aa-d9d2-4cc0-bf3b-f25ad4f3282b","html_url":"https://github.com/pranesh239/use-key-capture","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pranesh239%2Fuse-key-capture","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pranesh239%2Fuse-key-capture/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pranesh239%2Fuse-key-capture/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pranesh239%2Fuse-key-capture/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pranesh239","download_url":"https://codeload.github.com/pranesh239/use-key-capture/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243730942,"owners_count":20338743,"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":["custom-hook","hacktoberfest","keyboard-events","react","react-hooks"],"created_at":"2024-07-30T23:00:43.345Z","updated_at":"2025-03-15T12:30:40.656Z","avatar_url":"https://github.com/pranesh239.png","language":"JavaScript","funding_links":[],"categories":["UI Utilities","Packages","UI Components"],"sub_categories":["Device Input","Device Input/User Action"],"readme":"![Downloads](https://img.shields.io/bundlephobia/minzip/use-key-capture?style=plastic)\n\n\u003ch1 align=\"center\"\u003e\nuse-key-capture ⌨️\n\u003c/h1\u003e\n\n\n\n\n\u003cp align=\"center\" style=\"font-size: 1.2rem;\"\u003eA custom hook to ease the key-press listeners of a target/global.\u003c/p\u003e\n\n\u003e Check the\n\u003e [demo](https://use-key-capture.netlify.app/)\n\u003e here\n\n\u003chr /\u003e\n\n## The problem\n\nListening for key-press might be tedious when it comes to listening for combination keys such as \u003ckbd\u003eCtrl\u003c/kbd\u003e + \u003ckbd\u003eShift\u003c/kbd\u003e + \u003ckbd\u003eA\u003c/kbd\u003e or the entered letter is a caps or small varient or a number.\n\n## The Solution\n\nuse-key-capture is a custom hook which will lets you not to worry about the key-press event. Just plugin in use-key-capture hook to the **target** you want to listen for key press event or by default it can listen for key-press event **globally**.It gives simple API, which helps you listen for complex key combinations with ease.\n\nExample: \u003ckbd\u003eCtrl\u003c/kbd\u003e + \u003ckbd\u003eShift\u003c/kbd\u003e + \u003ckbd\u003eA\u003c/kbd\u003e - `useKeyCapture` gives\n\n```js\n{\n    key: 'A',\n    isCaps: true,\n    isWithCtrl: true,\n    isWithShift: true\n}\n```\n\n## installation\n\n**npm**\n\n```bash\nnpm i use-key-capture\n```\n\n**yarn**\n\n```bash\nyarn add use-key-capture\n```\n\n## Usage\n\nThis same working demo is [here](https://use-key-capture.netlify.com/demo).\n\n```jsx\nimport React from 'react';\nimport useKey from 'use-key-capture';\nimport './styles.css';\n\nconst displayKeys = ['Q', 'W', 'E', 'R', 'T', 'Y', 'Backspace'];\n\nconst TargetEventComponent = () =\u003e {\n  /* \n    keyData - gives the data of pressed key, i.e) isCaps, isNumber, isWithShift. \n    getTargetProps - a prop getter to be given if a target (input, textarea) have \n    to be listened for key-press.\n    */\n  const { keyData, getTargetProps } = useKey();\n\n  const getIsActive = key =\u003e (keyData.key === key ? 'active' : '');\n\n  return (\n    \u003cdiv className=\"container-target\"\u003e\n      \u003cdiv className=\"message\"\u003e\n        Type QWERTY in the input element below. If the focus is outside the\n        target, we won't see any change.\n      \u003c/div\u003e\n      \u003cinput {...getTargetProps()} /\u003e\n      \u003cdiv className=\"container\"\u003e\n        {displayKeys.map(key =\u003e {\n          return (\n            \u003cdiv key={key} className={`box ${getIsActive(key)}`}\u003e\n              {key}\n            \u003c/div\u003e\n          );\n        })}\n      \u003c/div\u003e\n    \u003c/div\u003e\n  );\n};\n\nexport default TargetEventComponent;\n```\n\n## Props\n\n### keyData\n\nIt will be the most used props from `useKeyCapture`. It gives the key/key varient/key combinations pressed.\n\n| Property           | Type    |\n| ------------------ | ------- |\n| key                | String  |\n| isEnter            | Boolean |\n| isBackspace        | Boolean |\n| isEscape           | Boolean |\n| isCapsLock         | Boolean |\n| isTab              | Boolean |\n| isSpace            | Boolean |\n| isArrow            | Boolean |\n| isArrowRight       | Boolean |\n| isArrowLeft        | Boolean |\n| isArrowUp          | Boolean |\n| isArrowDown        | Boolean |\n| isWithShift        | Boolean |\n| isWithCtrl         | Boolean |\n| isWithMeta         | Boolean |\n| isWithAlt          | Boolean |\n| isCaps             | Boolean |\n| isSmall            | Boolean |\n| isNumber           | Boolean |\n| isSpecialCharacter | Boolean |\n\n### getTargetProps\n\n`type: function({})`\n\nA prop getter to be given if a target (input, textarea) have to be listened for key-press.\n\n### resetKeyData\n\n`type: function({})`\n\nIt will reset all the values in `keyData` props to the initial values.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpranesh239%2Fuse-key-capture","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpranesh239%2Fuse-key-capture","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpranesh239%2Fuse-key-capture/lists"}