1.0.9 • Published 6 years ago

hot-key v1.0.9

Weekly downloads
1
License
ISC
Repository
github
Last release
6 years ago

alt tag

Listens hotkeys events in browser.

  npm i hot-key

How to use?

const HotKey = require('hot-key')

const config = {

  // target node
  domNode: document.querySelector('.editor'),

  // delay after which pressing becomes non-active
  delay: 1000,

  // maximum number of combinations
  symbols: 3,

  // combinations rules
  rules: [
    {
      name: 'ctrl+z',
      codes: [17, 90],
    },
    {
      name: 'ctrl+shift+z',
      codes: [17, 16, 90],
    },
    {
      name: 'cmd+z',
      codes: [91, 90],
    },
    {
      name: 'cmd+shift+z',
      codes: [91, 16, 90],
    },
  ]

}


// create object
const hotKey = new HotKey(config)

// assign events
hotKey.on('ctrl+z', (event) => {

  console.log('history back')

  // in event.rule you can access to matched rule

})

hotKey.on('cmd+z', (event) => {

  console.log('history back')

})

// or like this
hotKey.on(['ctrl+shift+z', 'cmd+shift+z'], (event) => {

  console.log('history forward')

})

// also you can extend rules on the fly like this:
hotKey.setRules([
  ...hotKey.getRules()
  {
    name: 'cmd+a',
    codes: [91, 65],
  },
])

// start listen keyup and keydown events
hotKey.start()

// stop listen events
hotKey.stop()
1.0.9

6 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago