{"id":13397990,"url":"https://github.com/ccampbell/mousetrap","last_synced_at":"2025-05-13T15:08:13.151Z","repository":{"id":3816922,"uuid":"4897046","full_name":"ccampbell/mousetrap","owner":"ccampbell","description":"Simple library for handling keyboard shortcuts in Javascript","archived":false,"fork":false,"pushed_at":"2023-03-15T18:11:42.000Z","size":461,"stargazers_count":11748,"open_issues_count":239,"forks_count":969,"subscribers_count":173,"default_branch":"master","last_synced_at":"2025-05-06T15:03:22.028Z","etag":null,"topics":["javascript","keyboard","keyboard-shortcuts","mousetrap"],"latest_commit_sha":null,"homepage":"https://craig.is/killing/mice","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ccampbell.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}},"created_at":"2012-07-05T03:13:55.000Z","updated_at":"2025-05-06T07:56:15.000Z","dependencies_parsed_at":"2023-07-05T19:48:28.837Z","dependency_job_id":null,"html_url":"https://github.com/ccampbell/mousetrap","commit_stats":{"total_commits":347,"total_committers":27,"mean_commits":"12.851851851851851","dds":0.1412103746397695,"last_synced_commit":"2f9a476ba6158ba69763e4fcf914966cc72ef433"},"previous_names":[],"tags_count":28,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ccampbell%2Fmousetrap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ccampbell%2Fmousetrap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ccampbell%2Fmousetrap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ccampbell%2Fmousetrap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ccampbell","download_url":"https://codeload.github.com/ccampbell/mousetrap/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253765985,"owners_count":21960826,"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":["javascript","keyboard","keyboard-shortcuts","mousetrap"],"created_at":"2024-07-30T18:02:00.240Z","updated_at":"2025-05-13T15:08:13.093Z","avatar_url":"https://github.com/ccampbell.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","Repository","UI","Keyboard Wrappers","Keyboard Wrappers [🔝](#readme)","2. JavaScript 框架汇总","Utilities","Browser","键盘封装器"],"sub_categories":["Interaction","Runner","React Components","运行器","运行器e2e测试"],"readme":"# Mousetrap\n[![CDNJS](https://img.shields.io/cdnjs/v/mousetrap.svg)](https://cdnjs.com/libraries/mousetrap)\n\nMousetrap is a simple library for handling keyboard shortcuts in Javascript.\n\nIt is licensed under the Apache 2.0 license.\n\nIt is around **2kb** minified and gzipped and **4.5kb** minified, has no external dependencies, and has been tested in the following browsers:\n\n- Internet Explorer 6+\n- Safari\n- Firefox\n- Chrome\n\nIt has support for `keypress`, `keydown`, and `keyup` events on specific keys, keyboard combinations, or key sequences.\n\n## Getting started\n\n1. Include mousetrap on your page before the closing `\u003c/body\u003e` tag\n\n    ```html\n    \u003cscript src=\"/path/to/mousetrap.min.js\"\u003e\u003c/script\u003e\n    ```\n\n    or install `mousetrap` from `npm` and require it\n\n    ```js\n    var Mousetrap = require('mousetrap');\n    ```\n\n2. Add some keyboard events to listen for\n\n    ```html\n    \u003cscript\u003e\n        // single keys\n        Mousetrap.bind('4', function() { console.log('4'); });\n        Mousetrap.bind(\"?\", function() { console.log('show shortcuts!'); });\n        Mousetrap.bind('esc', function() { console.log('escape'); }, 'keyup');\n\n        // combinations\n        Mousetrap.bind('command+shift+k', function() { console.log('command shift k'); });\n\n        // map multiple combinations to the same callback\n        Mousetrap.bind(['command+k', 'ctrl+k'], function() {\n            console.log('command k or control k');\n\n            // return false to prevent default browser behavior\n            // and stop event from bubbling\n            return false;\n        });\n\n        // gmail style sequences\n        Mousetrap.bind('g i', function() { console.log('go to inbox'); });\n        Mousetrap.bind('* a', function() { console.log('select all'); });\n\n        // konami code!\n        Mousetrap.bind('up up down down left right left right b a enter', function() {\n            console.log('konami code');\n        });\n    \u003c/script\u003e\n    ```\n\n## Why Mousetrap?\n\nThere are a number of other similar libraries out there so what makes this one different?\n\n- There are no external dependencies, no framework is required\n- You are not limited to `keydown` events (You can specify `keypress`, `keydown`, or `keyup` or let Mousetrap choose for you).\n- You can bind key events directly to special keys such as `?` or `*` without having to specify `shift+/` or `shift+8` which are not consistent across all keyboards\n- It works with international keyboard layouts\n- You can bind Gmail like key sequences in addition to regular keys and key combinations\n- You can programatically trigger key events with the `trigger()` method\n- It works with the numeric keypad on your keyboard\n- The code is well documented/commented\n\n## Tests\n\nUnit tests are run with \u003ca href=\"https://mochajs.org/\"\u003emocha\u003c/a\u003e.\n\n### Running in browser\n\n[View it online](http://rawgit.com/ccampbell/mousetrap/master/tests/mousetrap.html) to check your browser compatibility. You may also download the repo and open `tests/mousetrap.html` in your browser.\n\n### Running with Node.js\n\n1. Install development dependencies\n\n    ```sh\n    cd /path/to/repo\n    npm install\n    ```\n\n3. Run tests\n\n    ```sh\n    npm test\n    ```\n\n## Documentation\n\nFull documentation can be found at https://craig.is/killing/mice\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fccampbell%2Fmousetrap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fccampbell%2Fmousetrap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fccampbell%2Fmousetrap/lists"}