{"id":16765214,"url":"https://github.com/devlato/react-shortcut","last_synced_at":"2025-03-17T02:31:22.419Z","repository":{"id":39063711,"uuid":"83617650","full_name":"devlato/react-shortcut","owner":"devlato","description":"Convenient React component that detects if the given key combination is pressed, and triggers a callback","archived":false,"fork":false,"pushed_at":"2023-01-05T22:16:48.000Z","size":7318,"stargazers_count":17,"open_issues_count":24,"forks_count":7,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-27T16:43:45.897Z","etag":null,"topics":["callback","hotkey","hotkeys","javascript","konami","konamicode","react","rodney","shortcut","shortcuts"],"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/devlato.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":"SECURITY.md","support":null},"funding":{"github":"devlato","custom":"http://paypal.me/devlatoau"}},"created_at":"2017-03-02T00:58:46.000Z","updated_at":"2024-09-07T13:46:58.000Z","dependencies_parsed_at":"2023-02-04T20:00:47.664Z","dependency_job_id":null,"html_url":"https://github.com/devlato/react-shortcut","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devlato%2Freact-shortcut","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devlato%2Freact-shortcut/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devlato%2Freact-shortcut/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devlato%2Freact-shortcut/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/devlato","download_url":"https://codeload.github.com/devlato/react-shortcut/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243837010,"owners_count":20355813,"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":["callback","hotkey","hotkeys","javascript","konami","konamicode","react","rodney","shortcut","shortcuts"],"created_at":"2024-10-13T05:28:46.648Z","updated_at":"2025-03-17T02:31:21.958Z","avatar_url":"https://github.com/devlato.png","language":"TypeScript","readme":"# react-shortcut\n\nConvenient React component that detects if the given key combination is pressed, and triggers a callback\n\n[![View on npm](https://badge.fury.io/js/react-shortcut.svg)](https://npmjs.org/package/react-shortcut)\n[![Master Build Status](https://github.com/devlato/react-shortcut/workflows/CI/badge.svg)](https://github.com/devlato/react-shortcut/actions?query=workflow%3ARelease)\n[![Release CI Status](https://github.com/devlato/react-shortcut/workflows/Publish/badge.svg)](https://github.com/devlato/react-shortcut/actions?query=workflow%3APublish)\n[![Maintainability](https://api.codeclimate.com/v1/badges/f426b7cb20cd324588ad/maintainability)](https://codeclimate.com/github/devlato/react-shortcut/maintainability)\n[![Test Coverage](https://api.codeclimate.com/v1/badges/f426b7cb20cd324588ad/test_coverage)](https://codeclimate.com/github/devlato/react-shortcut/test_coverage)\n[![Demo](https://img.shields.io/badge/Live%20Demo-Open-yellow)](https://devlato.github.io/react-shortcut/)\n[![Bundle size](./.github/size-badge.svg)](https://bundlephobia.com/result?p=react-shortcut)\n[![Downloads](https://img.shields.io/npm/dm/react-shortcut)](https://npmjs.org/package/react-shortcut)\n[![MIT License](https://img.shields.io/npm/l/react-shortcut)](https://npmjs.org/package/react-shortcut)\n[![Issues](https://img.shields.io/github/issues/devlato/react-shortcut)](https://github.com/devlato/react-shortcut/issues)\n\n## Installation\n\nWith npm:\n\n```sh\n$ npm install --save react-shortcut\n```\n\nOr with Yarn:\n\n```sh\n$ yarn add react-shortcut\n```\n\n## Using the component\n\nIs very simple and straightforward! There are just a couple of props to pass in.\n\n### Code example\n\n```typescript jsx\nimport ReactShortcut from 'react-shortcut';\n\n// ...\n// Somewhere in your component tree\n\u003cReactShortcut\n  keys={/* String or array of strings containing the keys to be pressed, in any supported format */}\n  onKeysPressed={/* Callback when target key combination is pressed */}\n/\u003e;\n```\n\n### Props\n\nAll the props are required.\n\n| Name            | Description                                                                                            | Type                            |\n| --------------- | ------------------------------------------------------------------------------------------------------ | ------------------------------- |\n| `keys`          | A string containing comma-separated key combinations or/and key sequences, or an array of such strings | A string or an array of strings |\n| `onKeysPressed` | A callback to be triggered when the user presses any of the specified key combinations                 | A function with no arguments    |\n\n### Key combinations and Key sequences\n\nThe component supports both **key combinations** and **key sequences**.\n\n#### Key combinations\n\nA **key combination** is a string of key names separated by a plus sign, that describes what keys the user has to press at the same time, to execute the callback specified using `onKeysPressed` prop.\n\nExamples: `Command+Shift+Left`, `Ctrl+P`.\n\nTo react on the keys combination(s) press, use the following format:\n\n```typescript jsx\nimport ReactShortcut from 'react-shortcut';\n\n// Pass in the shortcut keys\n\u003cReactShortcut\n    keys=\"command+k\"\n    onKeysPressed={doSomethingOnShortcutPress}\n/\u003e\n\n// ... or an array of shortcuts\n\u003cReactShortcut\n    keys={['command+k', 'command+m']}\n    onKeysPressed={doSomethingOnShortcutPress}\n/\u003e\n\n// ... or a string of comma-separated shortcuts\n\u003cReactShortcut\n    keys=\"command+k,command+m\"\n    onKeysPressed={doSomethingOnShortcutPress}\n/\u003e\n```\n\n#### Key sequences\n\nA **key sequence** is a string of key names separated by a space character, that lists out the keys the user has to press one by one, to trigger the callback specified using `onKeysPressed` prop.\n\nExamples: `Up Up Down Down Left Right Left Right B A Enter`, `k o n a m i`.\n\nTo react on the keys sequence(s) press, use the following format:\n\n```typescript jsx\nimport ReactShortcut from 'react-shortcut';\n\n// Pass in the shortcut keys\n\u003cReactShortcut\n    keys=\"k o n a m i\"\n    onKeysPressed={doSomethingOnShortcutPress}\n/\u003e\n\n// ... or an array of shortcuts\n\u003cReactShortcut\n    keys={['k o n a m i', 'm a r i o b r o s enter']}\n    onKeysPressed={doSomethingOnShortcutPress}\n/\u003e\n\n// ... or a string of comma-separated shortcuts\n\u003cReactShortcut\n    keys=\"k o n a m i,m a r i o b r o s enter\"\n    onKeysPressed={doSomethingOnShortcutPress}\n/\u003e\n```\n\n#### Mixed use\n\nMixing both modes is possible –just follow the same key combination/key sequence convention:\n\n```typescript jsx\nimport ReactShortcut from 'react-shortcut';\n\n// Array of shortcuts\n\u003cReactShortcut\n    keys={['k o n a m i', 'shift+command+m']}\n    onKeysPressed={doSomethingOnShortcutPress}\n/\u003e\n\n// ... or a string of comma-separated shortcuts\n\u003cReactShortcut\n    keys=\"k o n a m i,shift+command+m\"\n    onKeysPressed={doSomethingOnShortcutPress}\n/\u003e\n```\n\n## FAQ\n\n### Does it support TypeScript?\n\nIt does. Moreover, it's implemented in TypeScript.\n\n### Do I have to use \u003cReactShortcut /\u003e component only in the root level component?\n\nNope. The component adds a global keyboard event listener and doesn't prevent events from bubbling or capturing.\n\n### What if my app needs to support multiple shortcuts?\n\nJust use the component as many times as you need, just make sure the shortcuts aren't repeated.\n\n### Do I have to specify the shortcuts in lower case only?\n\nNo, the case doesn't matter.\n\n### Any open-source examples of using this library?\n\nThere's an official™️ one called [react-easter](https://www.npmjs.com/package/react-easter), for adding easter eggs triggered by the keypress.\n\n## License\n\nThe library is shipped \"as is\" under MIT License.\n\n## Contributing [![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/devlato/react-shortcut/issues)\n\nFeel free to contribute, but don't forget to write tests, mate/matess.\n","funding_links":["https://github.com/sponsors/devlato","http://paypal.me/devlatoau"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevlato%2Freact-shortcut","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevlato%2Freact-shortcut","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevlato%2Freact-shortcut/lists"}