All Projects → github → Hotkey

github / Hotkey

Licence: mit
Trigger an action on an element with a keyboard shortcut.

Programming Languages

javascript
184084 projects - #8 most used programming language
typescript
32286 projects

Projects that are alternatives of or similar to Hotkey

Sublimetutor
An interactive in-editor keyboard shortcuts tutorial for Sublime Text 3
Stars: ✭ 336 (-85.94%)
Mutual labels:  shortcuts
Spotify Shortcuts Ios12
This repository contains a list of all available Shortcuts to control Spotify as well as an update mechanism.
Stars: ✭ 34 (-98.58%)
Mutual labels:  shortcuts
Foundationextension
Foundation/Cocoa/UIKit extension kit. Reference document:
Stars: ✭ 115 (-95.19%)
Mutual labels:  shortcuts
Python Shortcuts
Create Siri Shortcuts with Python
Stars: ✭ 525 (-78.02%)
Mutual labels:  shortcuts
Gata
Bookmarks made better
Stars: ✭ 17 (-99.29%)
Mutual labels:  shortcuts
Manaflux
The app needs a rewrite. It might not work anymore. An assistant that can choose your runes, summoner spells, and item sets for League of Legends.
Stars: ✭ 57 (-97.61%)
Mutual labels:  shortcuts
Keymage
Yet Another JS Keybinding library
Stars: ✭ 325 (-86.4%)
Mutual labels:  shortcuts
Hotkeys
🤖 A declarative library for handling hotkeys in Angular applications
Stars: ✭ 158 (-93.39%)
Mutual labels:  shortcuts
Better Chrome Native Video
Add keyboard support to Chrome's native HTML5 video player.
Stars: ✭ 31 (-98.7%)
Mutual labels:  shortcuts
Shortcuts Js
A JavaScript iOS 12 Shortcuts creator
Stars: ✭ 1,278 (-46.5%)
Mutual labels:  shortcuts
Hotkeys
➷ A robust Javascript library for capturing keyboard input. It has no dependencies.
Stars: ✭ 5,165 (+116.2%)
Mutual labels:  shortcuts
Shortcutmapper
A visual keyboard shortcuts explorer for popular applications.
Stars: ✭ 657 (-72.5%)
Mutual labels:  shortcuts
Shrtcts
Make Anything an RStudio Shortcut
Stars: ✭ 71 (-97.03%)
Mutual labels:  shortcuts
Electron Localshortcut
Add keyboard shortcuts locally to a BrowserWindow instance, without using a Menu
Stars: ✭ 366 (-84.68%)
Mutual labels:  shortcuts
Shortcuts Swift
Write Shortcuts in Playgrounds
Stars: ✭ 116 (-95.14%)
Mutual labels:  shortcuts
Androidshortcuts
Example app for shortcuts
Stars: ✭ 335 (-85.98%)
Mutual labels:  shortcuts
Shortcuts
Super performant and feature rich shortcuts management library.
Stars: ✭ 40 (-98.33%)
Mutual labels:  shortcuts
Njt
njt (npm jump to): a quick navigation tool for npm packages
Stars: ✭ 179 (-92.51%)
Mutual labels:  shortcuts
Sketch Plugin Monster
A Sketch plugin for managing all plugin shortcuts.
Stars: ✭ 143 (-94.01%)
Mutual labels:  shortcuts
Xcactionbar
"Alfred for Xcode" plugin
Stars: ✭ 1,217 (-49.06%)
Mutual labels:  shortcuts

Hotkey Behavior

<button data-hotkey="Shift+?">Show help dialog</button>

Trigger an action on a target element when a key, or sequence of keys, is pressed on the keyboard. This triggers a focus event on form fields, or a click event on other elements.

By default, hotkeys are extracted from a target element's data-hotkey attribute, but this can be overridden by passing the hotkey to the registering function (install) as a parameter.

How is this used on GitHub?

All shortcuts (for example g i, ., Meta+k) within GitHub use hotkey to declare shortcuts in server side templates. This is used on almost every page on GitHub.

Installation

$ npm install @github/hotkey

Usage

HTML

<a href="/page/2" data-hotkey="j">Next</a>
<a href="/help" data-hotkey="Control+h">Help</a>
<a href="/rails/rails" data-hotkey="g c">Code</a>
<a href="/search" data-hotkey="s,/">Search</a>

See the list of KeyboardEvent key values for a list of supported key values.

JS

import {install} from '@github/hotkey'

// Install all the hotkeys on the page
for (const el of document.querySelectorAll('[data-hotkey]')) {
  install(el)
}

Alternatively, the hotkey(s) can be passed to the install function as a parameter e.g.:

for (const el of document.querySelectorAll('[data-shortcut]')) {
  install(el, el.dataset.shortcut)
}

To unregister a hotkey from an element, use uninstall:

import {uninstall} from '@github/hotkey'

for (const el of document.querySelectorAll('[data-hotkey]')) {
  uninstall(el)
}

Hotkey string format

  1. Hotkey matches against the event.key, and uses standard W3C key names for keys and modifiers as documented in UI Events KeyboardEvent key Values.
  2. At minimum a hotkey string must specify one bare key.
  3. Multiple hotkeys (aliases) are separated by a ,. For example the hotkey a,b would activate if the user typed a or b.
  4. Multiple keys separated by a blank space represent a key sequence. For example the hotkey g n would activate when a user types the g key followed by the n key.
  5. Modifier key combos are separated with a + and are prepended to a key in a consistent order as follows: Control+Alt+Meta+Shift+KEY.

Example

The following hotkey would match if the user typed the key sequence a and then b, OR if the user held down the Control, Alt and / keys at the same time.

"a b,Control+Alt+/"

🔬 Hotkey Mapper is a tool to help you determine the correct hotkey string for your key combination: https://github.github.io/hotkey/examples/hotkey_mapper.html

Key-sequence considerations

Two-key-sequences such as g c and g i are stored under the 'g' key in a nested object with 'c' and 'i' keys.

mappings =
  'c'     : <a href="https://github.com/rails/rails/issues/new" data-hotkey="c">New Issue</a>
  'g'     :
    'c'   : <a href="https://github.com/rails/rails" data-hotkey="g c">Code</a>
    'i'   : <a href="https://github.com/rails/rails/issues" data-hotkey="g i">Issues</a>

In this example, both g c and c could be available as hotkeys on the same page, but g c and g can't coexist. If the user presses g, the c hotkey will be unavailable for 1500 ms while we wait for either g c or g i.

Accessibility considerations

Character Key Shortcuts

Please note that adding this functionality to your site can be a drawback for certain users. Providing a way in your system to disable hotkeys or remap them makes sure that those users can still use your site (given that it's accessible to those users).

See "Understanding Success Criterion 2.1.4: Character Key Shortcuts" for further reading on this topic.

Interactive Elements

Wherever possible, hotkeys should be add to interactive and focusable elements. If a static element must be used, please follow the guideline in "Adding keyboard-accessible actions to static HTML elements".

Development

npm install
npm test

License

Distributed under the MIT license. See LICENSE for details.

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