All Projects → CurtisHumphrey → react-keyboard-shortcuts

CurtisHumphrey / react-keyboard-shortcuts

Licence: MIT License
A declarative library for handling hotkeys based on explicit priority in React applications

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to react-keyboard-shortcuts

Is Hotkey
Check whether a browser event matches a hotkey.
Stars: ✭ 211 (+817.39%)
Mutual labels:  keyboard, events, hotkeys
Hotkeys
➷ A robust Javascript library for capturing keyboard input. It has no dependencies.
Stars: ✭ 5,165 (+22356.52%)
Mutual labels:  keyboard, hotkeys, shortcuts
Chordly
Chordly is a javascript library that may be used to detect and act upon key sequences entered by a user.
Stars: ✭ 14 (-39.13%)
Mutual labels:  keyboard, events, hotkeys
hotkey
⌨️ cross-platform hotkey package
Stars: ✭ 82 (+256.52%)
Mutual labels:  keyboard, hotkeys, shortcuts
Shortcutmapper
A visual keyboard shortcuts explorer for popular applications.
Stars: ✭ 657 (+2756.52%)
Mutual labels:  keyboard, shortcuts
LowLevelInput.Net
A thread safe and event driven LowLevelMouse and LowLevelKeyboard Hook
Stars: ✭ 32 (+39.13%)
Mutual labels:  keyboard, events
Inputsystem
An efficient and versatile input system for Unity.
Stars: ✭ 1,013 (+4304.35%)
Mutual labels:  keyboard, events
keybind
ClojureScript key bindings (shortcut) library
Stars: ✭ 85 (+269.57%)
Mutual labels:  hotkeys, shortcuts
Keymage
Yet Another JS Keybinding library
Stars: ✭ 325 (+1313.04%)
Mutual labels:  hotkeys, shortcuts
Pyhooked
Pure Python hotkey hook, with thanks to pyHook and pyhk
Stars: ✭ 150 (+552.17%)
Mutual labels:  keyboard, hotkeys
quickey
⚡️ Quickey creates keyboard shortcuts for your web apps
Stars: ✭ 37 (+60.87%)
Mutual labels:  keyboard, shortcuts
React Hotkeys
React component to listen to keydown and keyup keyboard events, defining and dispatching keyboard shortcuts.
Stars: ✭ 279 (+1113.04%)
Mutual labels:  keyboard, hotkeys
Icanhazshortcut
simple shortcut manager for macOS
Stars: ✭ 204 (+786.96%)
Mutual labels:  hotkeys, shortcuts
Hotkeys
🤖 A declarative library for handling hotkeys in Angular applications
Stars: ✭ 158 (+586.96%)
Mutual labels:  hotkeys, shortcuts
use-keyboard-shortcut
A custom hook that allows adding keyboard shortcuts to React applications
Stars: ✭ 41 (+78.26%)
Mutual labels:  keyboard, shortcuts
mac-terminal-shortcuts
Useful and common terminal shortcuts for macOS
Stars: ✭ 39 (+69.57%)
Mutual labels:  keyboard, shortcuts
react-shortcut
Convenient React component that detects if the given key combination is pressed, and triggers a callback
Stars: ✭ 16 (-30.43%)
Mutual labels:  hotkeys, shortcuts
g910-gkey-macro-support
GKey support for Logitech G910 Keyboard on Linux
Stars: ✭ 85 (+269.57%)
Mutual labels:  keyboard, hotkeys
input-event
🎹 Read and parse input device(like mouse, keyboard, joystick and IR-Remote)'s event data.
Stars: ✭ 45 (+95.65%)
Mutual labels:  keyboard, events
jyutping
Cantonese Jyutping Keyboard for iOS. 粵語粵拼輸入法鍵盤
Stars: ✭ 23 (+0%)
Mutual labels:  keyboard

license npm

A declarative library for handling hotkeys based on explicit priority in React applications.

Feature Overview

  • Minimal and declarative API
  • Intuitive key commands thanks to Mousetrap
  • Explicit priority based event handling (see more later)

Inspired by

Difference in event handling

Most hotkey or shortcut managing libraries follow the focus tree for event handling. Meaning that the element that has focus tries its handler and if it does not process the hotkey allows its parent to try and so on up do the document root. However, there are many cases where one element has focus but another has the handler but they are not in each other linage.

          + root
          |
      +---+--------+
      |            |
      |            |
  +---+---+        +
  |       |        Text
  |       |
  +       +
  Back    Next

For example, let say that you have a text element that currently have focus but you want the hotkeys alt+b and alt+n to work for the back and next buttons. These two buttons are not in the focus tree but are cousins. You could in those other libraries set the handlers on the root, but that often means that the root either has to have those same redux actions or has to have a reference to the next and back button to make those handlers work. Both are messy. Instead react-keyboard-shortcuts allows the Back and Next button to register hotkeys that work globally (regardless of what element has focus).

When the Back and Next buttons mount their hotkeys are register. When they unmount their hotkeys are unregister (via a higher-order-component). Also if two or more components want to have handlers for the same sequence they each provide a priority explicitly that determines who gets first chance (think of it like the z-index for css).

Install

npm

npm install react-keyboard-shortcuts

yarn

yarn add react-keyboard-shortcuts

Usage

Easy Example

import React from 'react'
import {hotkeys} from 'react-keyboard-shortcuts'

class NextButton extends React.PureComponent {
  static propTypes = {
    onClick: PropTypes.func.isRequired,
  }

  hot_keys = {
    'alt+n': { // combo from mousetrap
      priority: 1,
      handler: (event) => this.props.onClick(),
    },
  }

  render () {
    return (
      <button onClick={this.props.onClick}> Next</button>
    )
  }
}

export default hotkeys(NextButton)

API

  • hotkeys([component], [options = {}])
    • options:
      • hot_key_property_name - defaults to hot_keys
  • handler ** return false if you do not want it to propagate to the next priority handler

Notes

  • If using with redux connect do the hotkey first then connect connect(mapStateToProps, actions)(hotkeys(NextButton))
  • hotkeys will work even in form elements (not Mousetrap's default behavior)

Extras

hotkey_display just a helper for display the keys to users

import {hotkey_display} from 'react-keyboard-shortcuts'

const tooltip = hotkey_display('alt+n') // on a mac this will return 'option'
const tooltip = hotkey_display('meta+n') // on a mac this will return '⌘'

Thanks

Thanks to @ccampbell for Mousetrap

License

MIT

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