{"id":18247824,"url":"https://github.com/npm-packages-collection/multi-key-handler","last_synced_at":"2025-04-04T15:31:48.875Z","repository":{"id":257803840,"uuid":"863671726","full_name":"npm-packages-collection/multi-key-handler","owner":"npm-packages-collection","description":"A utility class for handling multiple key events and executing a callback function based on the key states.","archived":false,"fork":false,"pushed_at":"2024-10-29T15:28:12.000Z","size":60,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-28T16:14:08.431Z","etag":null,"topics":["callback","events","keybinding"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/npm-packages-collection.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":null,"code_of_conduct":"CODE_OF_CONDUCT.md","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},"funding":{"github":["32teeth"],"buy_me_a_coffee":"32teeth"}},"created_at":"2024-09-26T17:45:27.000Z","updated_at":"2025-01-30T22:57:16.000Z","dependencies_parsed_at":null,"dependency_job_id":"8cbe5f93-2820-4048-ab0a-9da5dca0108c","html_url":"https://github.com/npm-packages-collection/multi-key-handler","commit_stats":null,"previous_names":["32teeth/multi-key-handler"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/npm-packages-collection%2Fmulti-key-handler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/npm-packages-collection%2Fmulti-key-handler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/npm-packages-collection%2Fmulti-key-handler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/npm-packages-collection%2Fmulti-key-handler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/npm-packages-collection","download_url":"https://codeload.github.com/npm-packages-collection/multi-key-handler/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247202912,"owners_count":20900869,"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","events","keybinding"],"created_at":"2024-11-05T09:33:50.855Z","updated_at":"2025-04-04T15:31:43.859Z","avatar_url":"https://github.com/npm-packages-collection.png","language":"JavaScript","funding_links":["https://github.com/sponsors/32teeth","https://buymeacoffee.com/32teeth"],"categories":[],"sub_categories":[],"readme":"\n# MultiKeyHandler\n\nThe `MultiKeyHandler` class allows you to handle multiple key combinations, including arrow keys, with customizable options for debugging and event handling.\n\n## Installation\n\nYou can install the package using npm:\n\n```bash\nnpm install multi-key-handler\n```\n\n## Usage\n\nCreate an instance of `MultiKeyHandler` and provide a callback function to execute when a key combination is pressed.\n\n### Example\n\n```javascript\nimport { MultiKeyHandler } from 'multi-key-handler';\n\nconst handler = new MultiKeyHandler((states) =\u003e {\n  console.log('Current key states:', states);\n}, {\n  keys: 'asdf', // Listen for 'a', 's', 'd', 'f' keys\n  arrows: true, // Enable arrow key handling\n  debug: true,  // Enable debug mode\n});\n```\n\n### Callback Function\n\nThe callback function receives an object containing the current state of the keys being pressed. Each key's state is either `true` (pressed) or `false` (released).\n\n```javascript\n(states) =\u003e {\n  console.log(states);\n  // Example output:\n  // {\n  //   a: true,\n  //   s: false,\n  //   d: true,\n  //   f: false,\n  //   up: false,\n  //   down: true\n  // }\n}\n```\n\n## API\n\n### Constructor\n\n```javascript\nnew MultiKeyHandler(callback, options);\n```\n\n- **callback**: A function that will be called whenever a key is pressed or released.\n- **options**: An optional object to configure the handler:\n  - **keys**: A string of keys to listen for.\n  - **arrows**: A boolean indicating if the arrow keys should be included (`true` or `false`).\n  - **debug**: A boolean to enable debug mode.\n\n### Methods\n\n#### `keymap` (Getter)\n\nReturns the currently configured keys as a string.\n\n```javascript\nconsole.log(handler.keymap); // 'asdf'\n```\n\n#### `keymap` (Setter)\n\nSets the keys to listen for. The input should be a string.\n\n```javascript\nhandler.keymap = 'qwer';\n```\n\n## Options\n\n| Option  | Type    | Default | Description                          |\n|---------|---------|---------|--------------------------------------|\n| keys    | string  | ''      | The keys to listen for.              |\n| arrows  | boolean | false   | Whether to include arrow keys.       |\n| debug   | boolean | false   | Enables debug mode.                  |\n\n## Debug Mode\n\nWhen debug mode is enabled, a table of the current key states will be printed to the console whenever a change occurs.\n\n```javascript\nnew MultiKeyHandler((states) =\u003e {}, { debug: true });\n```\n\n## License\n\nThis project is licensed under the MIT License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnpm-packages-collection%2Fmulti-key-handler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnpm-packages-collection%2Fmulti-key-handler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnpm-packages-collection%2Fmulti-key-handler/lists"}