All Projects → arthurtyukayev → use-keyboard-shortcut

arthurtyukayev / use-keyboard-shortcut

Licence: MIT license
A custom hook that allows adding keyboard shortcuts to React applications

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to use-keyboard-shortcut

Shortcutmapper
A visual keyboard shortcuts explorer for popular applications.
Stars: ✭ 657 (+1502.44%)
Mutual labels:  keyboard, shortcuts, keyboard-shortcuts
Hotkeys
➷ A robust Javascript library for capturing keyboard input. It has no dependencies.
Stars: ✭ 5,165 (+12497.56%)
Mutual labels:  keyboard, shortcuts, keyboard-shortcuts
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 (+104.88%)
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 (+121.95%)
Mutual labels:  keyboard, keyboard-shortcuts
Mousetrap
Simple library for handling keyboard shortcuts in Javascript
Stars: ✭ 10,937 (+26575.61%)
Mutual labels:  keyboard, keyboard-shortcuts
Switch Desktop
⚡️ Keyboard-driven commands to navigate your apps faster
Stars: ✭ 320 (+680.49%)
Mutual labels:  keyboard, keyboard-shortcuts
Combokeys
Web browser keyboard shortcuts. CommonJS, NPM.
Stars: ✭ 675 (+1546.34%)
Mutual labels:  keyboard, keyboard-shortcuts
Aquatouch
Dynamic Custom Macros for your MacBook TouchBar! (Supports 40+ Apps and Websites)
Stars: ✭ 125 (+204.88%)
Mutual labels:  keyboard, keyboard-shortcuts
input-remapper
🎮 An easy to use tool to change the mapping of your input device buttons.
Stars: ✭ 1,142 (+2685.37%)
Mutual labels:  keyboard, keyboard-shortcuts
quickey
⚡️ Quickey creates keyboard shortcuts for your web apps
Stars: ✭ 37 (-9.76%)
Mutual labels:  keyboard, shortcuts
Chromium Vim
Vim bindings for Google Chrome.
Stars: ✭ 2,150 (+5143.9%)
Mutual labels:  keyboard, keyboard-shortcuts
Keymapper
📱 An Android app that maps any keys to actions.
Stars: ✭ 207 (+404.88%)
Mutual labels:  keyboard, keyboard-shortcuts
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 (-46.34%)
Mutual labels:  keyboard, keyboard-shortcuts
Repeat
Cross-platform mouse/keyboard record/replay and automation hotkeys/macros creation, and more advanced automation features.
Stars: ✭ 763 (+1760.98%)
Mutual labels:  keyboard, keyboard-shortcuts
react-keyboard-shortcuts
A declarative library for handling hotkeys based on explicit priority in React applications
Stars: ✭ 23 (-43.9%)
Mutual labels:  keyboard, shortcuts
Ng Keyboard Shortcuts
Dead Simple Keyboard Shortcuts Management for Angular
Stars: ✭ 121 (+195.12%)
Mutual labels:  keyboard, keyboard-shortcuts
hotkey
⌨️ cross-platform hotkey package
Stars: ✭ 82 (+100%)
Mutual labels:  keyboard, shortcuts
ember-key-manager
A service for (un)binding keyboard up and down events.
Stars: ✭ 39 (-4.88%)
Mutual labels:  keyboard, keyboard-shortcuts
Keyboardjs
A JavaScript library for binding keyboard combos without the pain of key codes and key combo conflicts.
Stars: ✭ 1,881 (+4487.8%)
Mutual labels:  keyboard, keyboard-shortcuts
Powerkey
Remap your Macbook's power key to Forward Delete
Stars: ✭ 212 (+417.07%)
Mutual labels:  keyboard, keyboard-shortcuts

useKeyboardShortcut

npm version testing

Documentation | Live Example

A custom React hook that allows adding keyboard shortcuts to a React application.

import React from 'react'
import useKeyboardShortcut from 'use-keyboard-shortcut'

const App = () => {
  const { flushHeldKeys } = useKeyboardShortcut(
    ["Shift", "H"],
    shortcutKeys => console.log("Shift + H has been pressed."),
    { 
      overrideSystem: false,
      ignoreInputFields: false, 
      repeatOnHold: false 
    }
  );

  return (
    <div>Hello World</div>
  )
}

Documentation

const { flushHeldKeys } = useKeyboardShortcut(shortcutArray, callback, options)
Hook Return Type Description
flushHeldKeys Function Function to flush the array of held keys used for keydown tracking. This can help fixing "stuck" keys.
Hook Parameter Type Description
shortcutArray Array Array of KeyboardEvent.key strings. A full list of strings can be seen here
callback Function Function that is called once the keys have been pressed.
options Object Object containing some configuration options. See options section

Options

A list of possible options to put in the options object passed as the third parameters to the hook.

Option Default Description
overrideSystem false Overrides the default browser behavior for that specific keyboard shortcut. See caveats section
ignoreInputFields true Allows enabling and disabling the keyboard shortcuts when pressed inside of input fields.
repeatOnHold true Determines whether the callback function should fire on repeat when keyboard shortcut is held down.

Caveats

Flaky System Override Shortcuts There are some issues when it comes to overriding default keys such as Meta, Control, and Alt with more than two keys, i.e Meta + S + F, these combinations don't work as well as they should due to limitations set by the browsers. They have flaky performance. Using more than two keys in a keyboard shortcut works for keys that don't also handle browser actions such as Shift + S + F. However for keyboard shortcuts such as Meta + S + V will have flaky performance and some of the events maybe bubble up to the browser and open the browser's save dialog.

Some browsers just simply ignore Event.preventDefault() when it comes to specific browser actions. For example, on Chrome the shortcut Meta + S can be prevented sometimes from opening the Save Dialog, however the shortcut Meta + T cannot be prevented from opening a new tab. Results may vary depending on the browser.

Callback behavior or browser behavior that causes a system dialog to appear might perform poorly. During testing, the keyup listener doesn't fire in some browsers if the callback or overriden shortcut resulted in a dialog appearing. For example, creating a shortcut such as Meta + A that opens an alert(), may sometimes cause the keyup listener to not fire and cause keys to be "stuck".

Bugs / Problems

Please create an issue.

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].