New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

hotshot

Package Overview
Dependencies
Maintainers
2
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hotshot

A teeny tiny keyboard shortcuts library

latest
Source
npmnpm
Version
1.0.5
Version published
Weekly downloads
4.7K
536.93%
Maintainers
2
Weekly downloads
 
Created
Source

Hotshot.js

A teeny tiny keyboard shortcuts library

Usage

const hotshot = new Hotshot({
  //number of milliseconds we wait for user input before the callback is triggered
  //this is only done if there is also a shortcut with more chars available
  //e.g. if the user pressed gs and gsp is available then we wait
  //otherwise we trigger the callback right away
  waitForInputTime: 500, 
  seqs: [{
    keyCodes: [71, 83],
    callback: () => console.log('TRIGGER', 'G S')
  }, {
    keyCodes: [71, 83, 80],
    callback: () => console.log('TRIGGER', 'G S P')
  }, {
    keyCodes: [91, 13, 71, 83, 80],
    callback: () => console.log('TRIGGER', 'COMMAND ENTER G S P')
  }, {
    keyCodes: [38, 38, 40, 40, 37, 39, 37, 39, 66, 65],
    callback: () => console.log('TRIGGER', '↑ ↑ ↓ ↓ ← → ← → B A')
  }],
  combos: [{
    keyCodes: [91, 66],
    callback: () => console.log('TRIGGER', 'COMMAND+B')
  }]
});

hotshot.bindSeq([65, 66, 71], () => console.log('TRIGGER', 'A B G'));
hotshot.bindCombo([91, 65], () => console.log('TRIGGER', 'COMMAND+A'));

Development

  • Make sure you have the dev deps installed: yarn i
  • Run yarn run setup-hooks to setup a pre-push hook that asks you to test before you push
  • Make your changes in src/ and run yarn run build to build to build/
  • Run yarn test and make sure all tests still pass

Run yarn run watch to watch for changes in src/Hotshot.js. Run yarn run serve-test to serve the manual test file on localhost:9000/demo.html

Quickly Finding Keycodes

The bindings object works with key codes instead of actual letters for performance reasons. Want to quickly find the key codes you need for your shortcut? Use this jsbin.

Why not use an existing library like Mousetrap?

Mousetrap:

  • Does not currently support a combination of two and three letter sequences (details)
  • Supports IE 6+ which we don't really need. We support IE 11+ at the moment.
  • Spends extra time and code on string character to key code conversion. With Hotshot we went with just using key codes for performance gain.

Keywords

keyboard

FAQs

Package last updated on 27 Feb 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts