jaywcjlove /hotkeys

➷ A robust Javascript library for capturing keyboard input. It has no dependencies.

★ 7,137⑂ 417👁 69⑃ 326● 233▤ 117
JavaScriptMITCreated 2015-05-18jaywcjlove.github.io/hotkeys-js
Download: v4.1.2v4.1.2 ↓4.1.22026-11-06
+1
Daily
+5
Weekly
+10
Monthly
7,137
stars
417
forks
69
watchers
326
prs
233
issues
117
releases

README

Using my app is also a way to support me:
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  



 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 (~8kB) (gzipped: 3.8kB), and has no dependencies. It should not interfere with any JavaScript libraries or frameworks. Official document demo preview, compatibility test. More examples.

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


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);
  }
});



UMD (Universal Module Definition) - For CommonJS/AMD environments:

html




ES Module - For modern browsers with module support:

html

import hotkeys from 'https://unpkg.com/hotkeys-js/dist/hotkeys-js.js';
hotkeys('ctrl+a', function(event, handler){
  alert('you pressed ctrl+a!');
});



 Used in React

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.

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

Hotkeys.js has been tested and should work in.

shell
Internet Explorer 6+
Safari
Firefox
Chrome


 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, f1 through f19, num_0 through num_9, num_multiply, num_add, num_enter, num_subtract, num_decimal, num_divide.

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

 Defining Shortcuts

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

ts
declare interface HotkeysInterface extends HotkeysAPI {
  (key: string, method: KeyHandler): void;
  (key: string, scope: string, method: KeyHandler): void;
  (key: string, option: HotkeysOptions, method: KeyHandler): void;
  shift?: boolean;
  ctrl?: boolean;
  alt?: boolean;
  option?: boolean;
  control?: boolean;
  cmd?: boolean;
  command?: boolean;
}
declare interface HotkeysAPI {
  setScope: SetScope;
  getScope: GetScope;
  deleteScope: DeleteScope;
  getPressedKeyCodes: GetPressedKeyCodes;
  getPressedKeyString: GetPressedKeyString;
  getAllKeyCodes: GetAllKeyCodes;
  isPressed: IsPre

Top issues

Latest release

v4.1.2 v4.1.2 2026-11-06
Documentation v4.1.2: https://raw.githack.com/jaywcjlove/hotkeys/8bfc8b4/index.html  
Comparing Changes: https://github.com/jaywcjlove/hotkeys-js/compare/v4.1.1...v4.1.2  

bash
npm i [email protected]


- 🐞 fix: reset modifier state on window focus changes ref:0 (558) 28b0824 @blueDaydreaming725

Snapshot: 2026-11-16T09:23:14Z · Data license Apache-2.0 · JSON