{"id":22706792,"url":"https://github.com/bigbinary/neeto-hotkeys","last_synced_at":"2025-04-12T11:16:20.678Z","repository":{"id":206939639,"uuid":"716534973","full_name":"bigbinary/neeto-hotkeys","owner":"bigbinary","description":null,"archived":false,"fork":false,"pushed_at":"2025-01-09T13:45:39.000Z","size":486,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":16,"default_branch":"main","last_synced_at":"2025-04-12T11:16:13.010Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/bigbinary.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":"2023-11-09T10:41:05.000Z","updated_at":"2025-01-09T13:45:43.000Z","dependencies_parsed_at":null,"dependency_job_id":"25a67044-a82e-4f0c-bda5-462aab3e903e","html_url":"https://github.com/bigbinary/neeto-hotkeys","commit_stats":null,"previous_names":["bigbinary/neeto-hotkeys"],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bigbinary%2Fneeto-hotkeys","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bigbinary%2Fneeto-hotkeys/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bigbinary%2Fneeto-hotkeys/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bigbinary%2Fneeto-hotkeys/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bigbinary","download_url":"https://codeload.github.com/bigbinary/neeto-hotkeys/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248557847,"owners_count":21124168,"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":"2024-12-10T10:09:44.992Z","updated_at":"2025-04-12T11:16:20.657Z","avatar_url":"https://github.com/bigbinary.png","language":"JavaScript","readme":"# @bigbinary/neeto-hotkeys\n\nThe `neeto-hotkeys` package provides the `useHotKeys` hook, a versatile utility\nfor managing hotkeys in an application. This hook allows you to define specific\nhotkey combinations and associate them with corresponding handler functions. The\nassociated handler is invoked upon pressing the configured hotkey(s), enabling\nyou to execute actions in response to keyboard input.\n\n## Installation\n\n```zsh\nyarn add @bigbinary/neeto-hotkeys\n```\n\n### Arguments that the `useHotKeys` hook accepts:\n\n- `hotkey`: A string specifying the hotkey(s) to listen for. Hotkeys can be\n  defined in three formats: `sequential`, `simultaneous` \u0026 `single`.\n\n  1.  Sequential: Any keys separated by a space are considered sequential. The\n      handler is invoked when the user presses the keys in sequence. For\n      example, `s r` means that when the user presses `s` followed by an `r` the\n      corresponding `handler` will be invoked.\n  2.  Simultaneous: Simultaneous hotkeys require all specified keys to be\n      pressed at the same time to trigger the handler. For example,\n      `command+shift+r` means that when `command`, `shift`, `r` are pressed at\n      the same time the handler will be invoked.\n  3.  Single: As the name indicates, this denotes single keys like `r` , `k`,\n      `return` etc. Whenever `r` is pressed its corresponding handler will be\n      called.\n\n  The hotkey should be in MacOS format, the hook will take care of converting it\n  to the users platform(eg: command -\u003e ctrl for windows).\n\n  If we want to bind multiple hotkeys to the same handler we can pass in an\n  array like so `useHotkeys(['a', 'b'], handler)`.\n\n- `handler`: The function that should be invoked when the hotkey is pressed.\n\n  Handler will receive the original key `event`. This can be used to stop the\n  default browser action like so `event.preventDefault()`.\n\n- `config`: A config object which has 3 properties `mode`, `unbindOnUnmount` \u0026\n  `enabled`.\n\n  1.  mode: The available values for mode are `default`, `global` \u0026 `scoped`.\n      - default: It is the default mode. Handlers will only be called if the\n        user is outside of a textarea, input, or select element.\n      - global: Handlers will be fired even if the user is inside form elements\n        like textarea.\n      - scoped: It is used for scoping a hotkey to a DOM element. You can use\n        this option if you want to invoke the handlers only if the user is\n        focused in a specific `div`, `button`, `textarea` and so on. When this\n        mode is set the hook will return a `ref`, you need to attached that\n        `ref` to the element to which you need to scope the hotkey.\n  2.  unbindOnUnmount: By default its value will be `true`. If you don't want a\n      handler to be unregistered when a component is unmounted then set the\n      value to `false`.\n  3.  enabled: By default its value will be `true`. Setting this to `false` will\n      not register the hotkey.\n  4.  document: This is an optional property. If you want to listen for hotkeys\n      on an external document (e.g., an iframe), pass the reference of that\n      document using the `document` property in the `config` object. If you do\n      not provide this property, the hook will listen for hotkeys on the current\n      document by default.\n\n### Return value:\n\n- `inputRef`: A `ref` which needs to be attached to the input element to be\n  listened to.\n\n### Usage:\n\nFollowing illustrates the usage of `useHotKeys` hook in implementing shortcut\nfor Sidebar opening.\n\n```jsx\nimport useHotKeys from \"@bigbinary/neeto-hotkeys\";\n\n// openSidebar function will only be called if the user is focused inside the textarea and performs the key combination.\nconst ref = useHotKeys(\"command+shift+r\", openSidebar, {\n  mode: \"scoped\",\n});\n\nreturn (\n  \u003cdiv\u003e\n    \u003cdiv\u003eHello world\u003c/div\u003e\n    \u003ctextarea ref={ref}\u003e\u003c/textarea\u003e\n  \u003c/div\u003e\n);\n```\n\nHotkeys are a fundamental aspect of many applications, enhancing user efficiency\nand interactivity. The useHotKeys hook simplifies the implementation of these\nhotkeys by allowing you to specify the hotkey combinations in various formats,\nassociated handlers, and configuration options.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbigbinary%2Fneeto-hotkeys","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbigbinary%2Fneeto-hotkeys","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbigbinary%2Fneeto-hotkeys/lists"}