All Projects → RobertWHurst → Keyboardjs

RobertWHurst / Keyboardjs

Licence: mit
A JavaScript library for binding keyboard combos without the pain of key codes and key combo conflicts.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Keyboardjs

Chordly
Chordly is a javascript library that may be used to detect and act upon key sequences entered by a user.
Stars: ✭ 14 (-99.26%)
Mutual labels:  keyboard, keyboard-shortcuts, keyboard-events, keydown
ember-key-manager
A service for (un)binding keyboard up and down events.
Stars: ✭ 39 (-97.93%)
Mutual labels:  keyboard, keyboard-shortcuts, keyboard-events
react-keyevent
An easy-to-use keyboard event react component, Package size less than 3kb
Stars: ✭ 38 (-97.98%)
Mutual labels:  keyboard, keyboard-shortcuts, keyboard-events
re-pressed
re-pressed is a clojurescript library that handles keyboard events for re-frame applications.
Stars: ✭ 150 (-92.03%)
Mutual labels:  keyboard, keyboard-events, keydown
hidstream
Streaming HID events in Node.js
Stars: ✭ 52 (-97.24%)
Mutual labels:  keyboard, keyboard-events
global-keypress
Global key press event emitter.
Stars: ✭ 25 (-98.67%)
Mutual labels:  keyboard, keyboard-events
input-remapper
🎮 An easy to use tool to change the mapping of your input device buttons.
Stars: ✭ 1,142 (-39.29%)
Mutual labels:  keyboard, keyboard-shortcuts
Switch Desktop
⚡️ Keyboard-driven commands to navigate your apps faster
Stars: ✭ 320 (-82.99%)
Mutual labels:  keyboard-shortcuts, keyboard
Hotkeys
➷ A robust Javascript library for capturing keyboard input. It has no dependencies.
Stars: ✭ 5,165 (+174.59%)
Mutual labels:  keyboard-shortcuts, keyboard
Repeat
Cross-platform mouse/keyboard record/replay and automation hotkeys/macros creation, and more advanced automation features.
Stars: ✭ 763 (-59.44%)
Mutual labels:  keyboard-shortcuts, keyboard
Combokeys
Web browser keyboard shortcuts. CommonJS, NPM.
Stars: ✭ 675 (-64.11%)
Mutual labels:  keyboard-shortcuts, keyboard
Mousetrap
Simple library for handling keyboard shortcuts in Javascript
Stars: ✭ 10,937 (+481.45%)
Mutual labels:  keyboard-shortcuts, keyboard
Ng Keyboard Shortcuts
Dead Simple Keyboard Shortcuts Management for Angular
Stars: ✭ 121 (-93.57%)
Mutual labels:  keyboard-shortcuts, keyboard
use-keyboard-shortcut
A custom hook that allows adding keyboard shortcuts to React applications
Stars: ✭ 41 (-97.82%)
Mutual labels:  keyboard, keyboard-shortcuts
Evscript
A tiny sandboxed Dyon scripting environment for evdev input devices that lets you do e.g. xcape in Wayland
Stars: ✭ 91 (-95.16%)
Mutual labels:  keyboard-shortcuts, keyboard
MyAHKScript
An AutoHotkey script that I use on the daily basis for my PC. Comes with an installer that takes care of everything for you.
Stars: ✭ 22 (-98.83%)
Mutual labels:  keyboard, keyboard-shortcuts
Keymapper
📱 An Android app that maps any keys to actions.
Stars: ✭ 207 (-89%)
Mutual labels:  keyboard-shortcuts, keyboard
Powerkey
Remap your Macbook's power key to Forward Delete
Stars: ✭ 212 (-88.73%)
Mutual labels:  keyboard-shortcuts, keyboard
Shortcutmapper
A visual keyboard shortcuts explorer for popular applications.
Stars: ✭ 657 (-65.07%)
Mutual labels:  keyboard-shortcuts, keyboard
Quickcut
QuickCut is a cross-platform keyboard manager that both facilitates key mapping and allows the configuration of global hotkeys triggering user defined actions.
Stars: ✭ 84 (-95.53%)
Mutual labels:  keyboard-shortcuts, keyboard

KeyboardJS

Build Status NPM Version Downloads This Week License

KeyboardJS is a library for use in the browser (node.js compatible). It Allows developers to easily setup key bindings. Use key combos to setup complex bindings. KeyboardJS also provides contexts. Contexts are great for single page applications. They allow you to scope your bindings to various parts of your application. Out of the box keyboardJS uses a US keyboard locale. If you need support for a different type of keyboard KeyboardJS provides custom locale support so you can create with a locale that better matches your needs.

KeyboardJS is available as a NPM module. If you're not using a build system like webpack, simply add keyboard.js or keyboard.min.js from the dist folder in this repo to your project via a script tag.

npm install keyboardjs

Note that all key names can be found in ./locales/us.js.

Setting up bindings is easy

keyboardJS.bind('a', (e) => {
  console.log('a is pressed');
});
keyboardJS.bind('a + b', (e) => {
  console.log('a and b is pressed');
});
keyboardJS.bind('a + b > c', (e) => {
  console.log('a and b then c is pressed');
});
keyboardJS.bind(['a + b > c', 'z + y > z'], (e) => {
  console.log('a and b then c or z and y then z is pressed');
});
keyboardJS.bind('', (e) => {
  console.log('any key was pressed');
});
//alt, shift, ctrl, etc must be lowercase
keyboardJS.bind('alt + shift > a', (e) => {
  console.log('alt, shift and a is pressed');
});

// keyboardJS.bind === keyboardJS.on === keyboardJS.addListener

keydown vs a keyup

keyboardJS.bind('a', (e) => {
  console.log('a is pressed');
}, (e) => {
  console.log('a is released');
});
keyboardJS.bind('a', null, (e) => {
  console.log('a is released');
});

Prevent keydown repeat

keyboardJS.bind('a', (e) => {
  // this will run once even if a is held
  e.preventRepeat();
  console.log('a is pressed');
});

Unbind things

keyboardJS.unbind('a', previouslyBoundHandler);
// keyboardJS.unbind === keyboardJS.off === keyboardJS.removeListener

Using contexts

  // these will execute in all contexts
  keyboardJS.bind('a', (e) => {});
  keyboardJS.bind('b', (e) => {});
  keyboardJS.bind('c', (e) => {});

  // these will execute in the index context
  keyboardJS.setContext('index');
  keyboardJS.bind('1', (e) => {});
  keyboardJS.bind('2', (e) => {});
  keyboardJS.bind('3', (e) => {});

  // these will execute in the foo context
  keyboardJS.setContext('foo');
  keyboardJS.bind('x', (e) => {});
  keyboardJS.bind('y', (e) => {});
  keyboardJS.bind('z', (e) => {});

  // if we have a router we can activate these contexts when appropriate
  myRouter.on('/', (e) => {
    keyboardJS.setContext('index');
  });
  myRouter.on('/foo', (e) => {
    keyboardJS.setContext('foo');
  });

  // you can always figure out your context too
  const contextName = keyboardJS.getContext();

  // you can also set up handlers for a context without losing the current context
  keyboardJS.withContext('bar', ()  =>{
    // these will execute in the bar context
    keyboardJS.bind('7', (e) => {});
    keyboardJS.bind('8', (e) => {});
    keyboardJS.bind('9', (e) => {});
  });

pause, resume, and reset

// the keyboard will no longer trigger bindings
keyboardJS.pause();

// the keyboard will once again trigger bindings
keyboardJS.resume();

// all active bindings will released and unbound,
// pressed keys will be cleared
keyboardJS.reset();

pressKey, releaseKey, and releaseAllKeys

// pressKey
keyboardJS.pressKey('a');
// or
keyboardJS.pressKey(65);

// releaseKey
keyboardJS.releaseKey('a');
// or
keyboardJS.releaseKey(65);

// releaseAllKeys
keyboardJS.releaseAllKeys();

watch and stop

// bind to the window and document in the current window
keyboardJS.watch();

// or pass your own window and document
keyboardJS.watch(myDoc);
keyboardJS.watch(myWin, myDoc);

// or scope to a specific element
keyboardJS.watch(myForm);
keyboardJS.watch(myWin, myForm);

// detach KeyboardJS from the window and document/element
keyboardJS.stop();
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].