PHPackages                             gaomingcode/hotkeys - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. gaomingcode/hotkeys

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

gaomingcode/hotkeys
===================

A simple micro-library for defining and dispatching keyboard shortcuts. It has no dependencies.

3.8.5(4y ago)08MITJavaScript

Since Jun 5Pushed 4y agoCompare

[ Source](https://github.com/gaomingcode/hotkeys)[ Packagist](https://packagist.org/packages/gaomingcode/hotkeys)[ Docs](http://jaywcjlove.github.io/hotkeys)[ Fund](https://jaywcjlove.github.io/sponsor.html)[ GitHub Sponsors](https://github.com/jaywcjlove)[ RSS](/packages/gaomingcode-hotkeys/feed)WikiDiscussions master Synced 5d ago

READMEChangelog (1)DependenciesVersions (2)Used By (0)

Hotkeys
=======

[](#hotkeys)

[![GitHub Version](https://camo.githubusercontent.com/39610cf1dffa1f12a38566bff0c119f6a7324e2718378a3b10242a8e4119073e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f67616f6d696e67636f64652f686f746b6579732e737667)](https://github.com/gaomingcode/hotkeys)[![Packagist Downloads](https://camo.githubusercontent.com/bff5bd02c718d1c488dd71827ef80e5b26cb5d2b6af1d298a141c420901a6866/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f67616f6d696e67636f64652f686f746b657973)](https://github.com/gaomingcode/hotkeys)[![Github License](https://camo.githubusercontent.com/928c9d11b58935b98583c26fb00ecd40ab6a3b7a7fdd64cb2284f16ea8c9e6f4/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f67616f6d696e67636f64652f686f746b657973)](https://github.com/gaomingcode/hotkeys)

Installation
------------

[](#installation)

### Composer

[](#composer)

```
composer require gaomingcode/hotkeys

```

ReadMe from Origin
------------------

[](#readme-from-origin)

[![](https://camo.githubusercontent.com/d6db4431e7802cda86d43d1e719dfec6b34e67c0c0d021205a96187eabbe7be9/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f6a617977636a6c6f76652f686f746b6579732e737667)](https://github.com/jaywcjlove/hotkeys/issues) [![](https://camo.githubusercontent.com/5068f5685f1e62cda49061b602fe3150325c120d379411e5f4d714eaa9d7aae0/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f666f726b732f6a617977636a6c6f76652f686f746b6579732e737667)](https://github.com/jaywcjlove/hotkeys/network) [![](https://camo.githubusercontent.com/aeae57fed6de0d5c6d6d9404a5dd19d28b9aec533d40b162828167342c5b5ecd/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f6a617977636a6c6f76652f686f746b6579732e737667)](https://github.com/jaywcjlove/hotkeys/stargazers) [![](https://camo.githubusercontent.com/38f643f9449d8f568ebe35b36fee93f4c78db1b59f6485c12aa1d0c84ca87515/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f6a617977636a6c6f76652f686f746b6579732e737667)](https://github.com/jaywcjlove/hotkeys/releases) [![](https://camo.githubusercontent.com/de8d359afd8b7d32383243c4a7e1f19743e2f936fb2940b75d32ac1d2074a039/687474703a2f2f6a617977636a6c6f76652e6769746875622e696f2f73622f7374617475732f6e6f2d646570656e64656e636965732e737667)](https://camo.githubusercontent.com/de8d359afd8b7d32383243c4a7e1f19743e2f936fb2940b75d32ac1d2074a039/687474703a2f2f6a617977636a6c6f76652e6769746875622e696f2f73622f7374617475732f6e6f2d646570656e64656e636965732e737667) [![Build Status](https://camo.githubusercontent.com/bb168d16e36b29c0947ba8661e5475e6920cc97b86078acbadfb56221b160c4e/68747470733a2f2f7777772e7472617669732d63692e6f72672f6a617977636a6c6f76652f686f746b6579732e7376673f6272616e63683d6d6173746572)](https://www.travis-ci.org/jaywcjlove/hotkeys) [![Coverage Status](https://camo.githubusercontent.com/27dc6517f008811e6928089c6dc0851c7c222cbffc56eebd4c8d1b508efabf95/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6a617977636a6c6f76652f686f746b6579732f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/jaywcjlove/hotkeys?branch=master) [![jaywcjlove/hotkeys](https://camo.githubusercontent.com/7d62ed7804673df9c7b36cf73b14f355a2e7900dd57a0f6d6d7fcb6efbe54829/68747470733a2f2f6a617977636a6c6f76652e6769746875622e696f2f73622f6c616e672f6368696e6573652e737667)](./README-zh.md) [![jaywcjlove/hotkeys](https://camo.githubusercontent.com/6c852f29d5385be182ecf504c96408add5f4743e32d66fa87afbcec5820746a2/68747470733a2f2f6a617977636a6c6f76652e6769746875622e696f2f73622f69636f2f67697465652e737667)](https://gitee.com/jaywcjlove/hotkeys)

HotKeys.js is an input capture library with some very special features, it is easy to pick up and use, has a reasonable footprint ([~3kb](https://bundlephobia.com/result?p=hotkeys-js)) (gzipped: 1.73kb), and has no dependencies. It should not interfere with any JavaScript libraries or frameworks. Official document [demo preview](http://jaywcjlove.github.io/hotkeys). [More examples](https://github.com/jaywcjlove/hotkeys/issues?q=label%3ADemo+).

```
╭┈┈╮          ╭┈┈╮  ╭┈┈╮
┆  ├┈┈..┈┈┈┈┈.┆  └┈╮┆  ├┈┈..┈┈┈┈┈..┈┈.┈┈..┈┈┈┈┈.
┆     ┆┆  □  ┆┆   ┈┤┆

hotkeys('ctrl+a,ctrl+b,r,f', function (event, handler){
  switch (handler.key) {
    case 'ctrl+a': alert('you pressed ctrl+a!');
      break;
    case 'ctrl+b': alert('you pressed ctrl+b!');
      break;
    case 'r': alert('you pressed r!');
      break;
    case 'f': alert('you pressed f!');
      break;
    default: alert(event);
  }
});

```

### Used in React

[](#used-in-react)

[react-hotkeys](https://github.com/jaywcjlove/react-hotkeys) is the React component that listen to keydown and keyup keyboard events, defining and dispatching keyboard shortcuts. Detailed use method please see its documentation [react-hotkeys](https://github.com/jaywcjlove/react-hotkeys).

[react-hotkeys-hook](https://github.com/JohannesKlauss/react-hotkeys-hook) - React hook for using keyboard shortcuts in components. Make sure that you have at least version 16.8 of react and react-dom installed, or otherwise hooks won't work for you.

Browser Support
---------------

[](#browser-support)

Hotkeys.js has been tested and should work in.

```
Internet Explorer 6+
Safari
Firefox
Chrome
```

Supported Keys
--------------

[](#supported-keys)

HotKeys understands the following modifiers: `⇧`, `shift`, `option`, `⌥`, `alt`, `ctrl`, `control`, `command`, and `⌘`.

The following special keys can be used for shortcuts: backspace, tab, clear, enter, return, esc, escape, space, up, down, left, right, home, end, pageup, pagedown, del, delete and f1 through f19.

`⌘` Command()
`⌃` Control
`⌥` Option(alt)
`⇧` Shift
`⇪` Caps Lock(Capital)
`fn` Does not support fn
`↩︎` return/Enter space

Defining Shortcuts
------------------

[](#defining-shortcuts)

One global method is exposed, key which defines shortcuts when called directly.

```
hotkeys([keys:], [option:[string|object|function]], [callback:])
```

```
hotkeys('f5', function(event, handler) {
  // Prevent the default refresh event under WINDOWS system
  event.preventDefault();
  alert('you pressed F5!');
});

// Returning false stops the event and prevents default browser events
// Mac OS system defines `command + r` as a refresh shortcut
hotkeys('ctrl+r, command+r', function() {
  alert('stopped reload!');
  return false;
});

// Single key
hotkeys('a', function(event,handler){
  //event.srcElement: input
  //event.target: input
  if(event.target === "input"){
      alert('you pressed a!')
  }
  alert('you pressed a!')
});

// Key Combination
hotkeys('ctrl+a,ctrl+b,r,f', function (event, handler){
  switch (handler.key) {
    case 'ctrl+a': alert('you pressed ctrl+a!');
      break;
    case 'ctrl+b': alert('you pressed ctrl+b!');
      break;
    case 'r': alert('you pressed r!');
      break;
    case 'f': alert('you pressed f!');
      break;
    default: alert(event);
  }
});

hotkeys('ctrl+a+s', function() {
    alert('you pressed ctrl+a+s!');
});

// Using a scope
hotkeys('*','wcj', function(event){
  console.log('do something', event);
});
```

#### option

[](#option)

- `scope`
- `element`
- `keyup`
- `keydown`
- `splitKey` (default is `+`)

```
hotkeys('o, enter', {
  scope: 'wcj',
  element: document.getElementById('wrapper'),
}, function(){
  console.log('do something else');
});

hotkeys('ctrl-+', { splitKey: '-' }, function(e) {
  console.log('you pressed ctrl and +');
});

hotkeys('+', { splitKey: '-' }, function(e){
  console.log('you pressed +');
})
```

API REFERENCE
-------------

[](#api-reference)

Asterisk "\*"

Modifier key judgments

```
hotkeys('*', function() {
  if (hotkeys.shift) {
    console.log('shift is pressed!');
  }

  if (hotkeys.ctrl) {
    console.log('ctrl is pressed!');
  }

  if (hotkeys.alt) {
    console.log('alt is pressed!');
  }

  if (hotkeys.option) {
    console.log('option is pressed!');
  }

  if (hotkeys.control) {
    console.log('control is pressed!');
  }

  if (hotkeys.cmd) {
    console.log('cmd is pressed!');
  }

  if (hotkeys.command) {
    console.log('command is pressed!');
  }
});
```

### setScope

[](#setscope)

Use the `hotkeys.setScope` method to set scope. There can only be one active scope besides 'all'. By default 'all' is always active.

```
// Define shortcuts with a scope
hotkeys('ctrl+o, ctrl+alt+enter', 'issues', function(){
  console.log('do something');
});
hotkeys('o, enter', 'files', function(){
  console.log('do something else');
});

// Set the scope (only 'all' and 'issues' shortcuts will be honored)
hotkeys.setScope('issues'); // default scope is 'all'
```

### getScope

[](#getscope)

Use the `hotkeys.getScope` method to get scope.

```
hotkeys.getScope();
```

### deleteScope

[](#deletescope)

Use the `hotkeys.deleteScope` method to delete a scope. This will also remove all associated hotkeys with it.

```
hotkeys.deleteScope('issues');
```

### unbind

[](#unbind)

Similar to defining shortcuts, they can be unbound using `hotkeys.unbind`.

```
// unbind 'a' handler
hotkeys.unbind('a');

// Unbind a hotkeys only for a single scope
// If no scope is specified it defaults to the current scope (hotkeys.getScope())
hotkeys.unbind('o, enter', 'issues');
hotkeys.unbind('o, enter', 'files');
```

Unbind events through functions.

```
function example() {
  hotkeys('a', example);
  hotkeys.unbind('a', example);

  hotkeys('a', 'issues', example);
  hotkeys.unbind('a', 'issues', example);
}
```

To unbind everything.

```
hotkeys.unbind();
```

### isPressed

[](#ispressed)

For example, `hotkeys.isPressed(77)` is true if the `M` key is currently pressed.

```
hotkeys('a', function() {
  console.log(hotkeys.isPressed('a')); //=> true
  console.log(hotkeys.isPressed('A')); //=> true
  console.log(hotkeys.isPressed(65)); //=> true
});
```

keyup
-----

[](#keyup)

**key down** and **key up** both perform callback events.

```
hotkeys('ctrl+a,alt+a+s', {keyup: true}, function(event, handler) {
  if (event.type === 'keydown') {
    console.log('keydown:', event.type, handler, handler.key);
  }

  if (event.type === 'keyup') {
    console.log('keyup:', event.type, handler, handler.key);
  }
});
```

### getPressedKeyCodes

[](#getpressedkeycodes)

Returns an array of key codes currently pressed.

```
hotkeys('command+ctrl+shift+a,f', function(){
  console.log(hotkeys.getPressedKeyCodes()); //=> [17, 65] or [70]
})
```

### filter

[](#filter)

By default hotkeys are not enabled for `INPUT` `SELECT` `TEXTAREA` elements. `Hotkeys.filter` to return to the `true` shortcut keys set to play a role, `false` shortcut keys set up failure.

```
hotkeys.filter = function(event){
  return true;
}
//How to add the filter to edit labels.
//"contentEditable" Older browsers that do not support drops
hotkeys.filter = function(event) {
  var tagName = (event.target || event.srcElement).tagName;
  return !(tagName.isContentEditable || tagName == 'INPUT' || tagName == 'SELECT' || tagName == 'TEXTAREA');
}

hotkeys.filter = function(event){
  var tagName = (event.target || event.srcElement).tagName;
  hotkeys.setScope(/^(INPUT|TEXTAREA|SELECT)$/.test(tagName) ? 'input' : 'other');
  return true;
}
```

### noConflict

[](#noconflict)

Relinquish HotKeys’s control of the `hotkeys` variable.

```
var k = hotkeys.noConflict();
k('a', function() {
  console.log("do something")
});

hotkeys()
// -->Uncaught TypeError: hotkeys is not a function(anonymous function)
// @ VM2170:2InjectedScript._evaluateOn
// @ VM2165:883InjectedScript._evaluateAndWrap
// @ VM2165:816InjectedScript.evaluate @ VM2165:682
```

Development
-----------

[](#development)

To develop, Install dependencies, Get the code:

```
$ git https://github.com/jaywcjlove/hotkeys.git
$ cd hotkeys     # Into the directory
$ npm install    # or  yarn install
```

To develop, run the self-reloading build:

```
$ npm run watch
```

Run Document Website Environment.

```
$ npm run doc
```

To contribute, please fork Hotkeys.js, add your patch and tests for it (in the `test/` folder) and submit a pull request.

```
$ npm run test
$ npm run test:watch # Development model
```

License
-------

[](#license)

[MIT © Kenny Wong](./LICENSE)

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 78.1% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

1806d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4b333bd44a2f7f526cc29a59b2945b27c7d2f31df68b92c2eb46efbddc032483?d=identicon)[gaomingcode](/maintainers/gaomingcode)

---

Top Contributors

[![jaywcjlove](https://avatars.githubusercontent.com/u/1680273?v=4)](https://github.com/jaywcjlove "jaywcjlove (325 commits)")[![renovate[bot]](https://avatars.githubusercontent.com/in/2740?v=4)](https://github.com/renovate[bot] "renovate[bot] (39 commits)")[![renovate-bot](https://avatars.githubusercontent.com/u/25180681?v=4)](https://github.com/renovate-bot "renovate-bot (8 commits)")[![yyjjqq94](https://avatars.githubusercontent.com/u/26669481?v=4)](https://github.com/yyjjqq94 "yyjjqq94 (6 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (5 commits)")[![liuzi6612](https://avatars.githubusercontent.com/u/15535177?v=4)](https://github.com/liuzi6612 "liuzi6612 (2 commits)")[![sk-](https://avatars.githubusercontent.com/u/911768?v=4)](https://github.com/sk- "sk- (2 commits)")[![JounQin](https://avatars.githubusercontent.com/u/8336744?v=4)](https://github.com/JounQin "JounQin (2 commits)")[![nikteg](https://avatars.githubusercontent.com/u/2521318?v=4)](https://github.com/nikteg "nikteg (2 commits)")[![xjh22222228](https://avatars.githubusercontent.com/u/15535177?v=4)](https://github.com/xjh22222228 "xjh22222228 (2 commits)")[![egorshar](https://avatars.githubusercontent.com/u/286997?v=4)](https://github.com/egorshar "egorshar (2 commits)")[![gaomingcode](https://avatars.githubusercontent.com/u/53959161?v=4)](https://github.com/gaomingcode "gaomingcode (2 commits)")[![smar152](https://avatars.githubusercontent.com/u/54095151?v=4)](https://github.com/smar152 "smar152 (1 commits)")[![Smona](https://avatars.githubusercontent.com/u/7091399?v=4)](https://github.com/Smona "Smona (1 commits)")[![spencer516](https://avatars.githubusercontent.com/u/2889608?v=4)](https://github.com/spencer516 "spencer516 (1 commits)")[![toddmacintyre](https://avatars.githubusercontent.com/u/17246907?v=4)](https://github.com/toddmacintyre "toddmacintyre (1 commits)")[![vitormv](https://avatars.githubusercontent.com/u/183328?v=4)](https://github.com/vitormv "vitormv (1 commits)")[![weidapao](https://avatars.githubusercontent.com/u/25810186?v=4)](https://github.com/weidapao "weidapao (1 commits)")[![yakov116](https://avatars.githubusercontent.com/u/16872793?v=4)](https://github.com/yakov116 "yakov116 (1 commits)")[![mdwork1](https://avatars.githubusercontent.com/u/70951882?v=4)](https://github.com/mdwork1 "mdwork1 (1 commits)")

---

Tags

keyshortcutskeyskeyboardhotkeyhotkeysjshotkeys-jshotkeyskeypress

### Embed Badge

![Health badge](/badges/gaomingcode-hotkeys/health.svg)

```
[![Health](https://phpackages.com/badges/gaomingcode-hotkeys/health.svg)](https://phpackages.com/packages/gaomingcode-hotkeys)
```

###  Alternatives

[gladcodes/keygen

A fluent PHP random key generator.

119668.9k2](/packages/gladcodes-keygen)[undefinedoffset/silverstripe-keyboardshortcuts

Adds keyboard shortcuts for common tasks to SilverStripe 4.0+ (ctrl/command+s for save anyone?)

1811.8k](/packages/undefinedoffset-silverstripe-keyboardshortcuts)[andrewcarteruk/cryptokey

A command line tool for generating keys using a CSPRNG.

6124.2k](/packages/andrewcarteruk-cryptokey)[adamhopkinson/laravel-model-hash

A trait which automatically generates a unique hash per model instance

2318.7k](/packages/adamhopkinson-laravel-model-hash)[codeaken/sshkey

Library for working with and generating SSH keys

1260.0k1](/packages/codeaken-sshkey)[infocyph/uid

UUID (RFC 4122 + Unofficial/Draft), ULID, Snowflake ID, Sonyflake ID, TBSL (library exclusive) generator!

105.1k](/packages/infocyph-uid)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
