2.1.0 • Published 4 years ago

keypress-tool v2.1.0

Weekly downloads
5
License
LGPL-3.0
Repository
github
Last release
4 years ago

keypress-tool

Build Status Dependencies Development Dependencies

npm

Usage

import KeyPress from 'keypress-tool';

// Calling it with the same parameters returns identical objects
KeyPress('A', 'ctrl') === KeyPress('A', 'ctrl'); // true
KeyPress('A', 'ctrl') === KeyPress('A', 'ctrl', 'shift'); // false

// Add listeners like this
KeyPress('A', 'shift').addListener(ev => {
  console.log('Key combination pressed');
});

// Set the second parameter to true if this listener should also fire during text input
KeyPress('A').addListener(handleEvent, true);

function handleEvent(event) {
  console.log('Key combination pressed');
}

// Clean up (very important to avoid memory leaks)
KeyPress('A').removeListener(handleEvent);

// The default is to preventDefault. Pass 'executeDefault' if you want to change this
KeyPress('A', 'executeDefault');

// Generate a short description of the key combination
let k = KeyPress('A', 'ctrl', 'shift', 'alt', 'meta');
k.toString(); // 'Win+Ctrl+Alt+Shift+A' on most platforms
k.toString(); // '⌃⌥⇧⌘A' on macOS

Only these special keys work in fullscreen in Safari:

Tab, Enter, Space, Left, Up, Right, Down, ; = , - . / ` [ ] '

See also:

Contributing

Download source and compile:

git clone git@github.com:JannesMeyer/keypress-tool.git
yarn

Compile and watch for file changes:

yarn start

Run tests:

yarn test

Pull requests welcome. Please respect the existing formatting and indentation style. Furthermore, please add tests for code that you contribute.

License

LGPL v3.0

2.1.0

4 years ago

2.0.0

6 years ago

1.0.10

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

8 years ago

1.0.4

9 years ago

1.0.3

9 years ago

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago