hotkeys-js icon indicating copy to clipboard operation
hotkeys-js copied to clipboard

How to prevent hotkey to trigger event again and again if key is pressed?

Open ervishal89 opened this issue 5 years ago • 2 comments

Hi,

import hotkeys from 'hotkeys-js';

hotkeys('ctrl+s', function (e) { alert('do something', e); });

If I keep holding ctrl+s, this event keep getting fired, Is there a way to stop that?

ervishal89 avatar Mar 21 '19 04:03 ervishal89

@ervishal89 Upgrade [email protected].

key down and key up both perform callback events.

hotkeys('ctrl+a,alt+a+s', { keyup: true }, (evn, handler) => {
  if(evn.type === 'keydown') {
    console.log('keydown:', evn.type, handler, handler.key);
  }
  if(evn.type === 'keyup') {
    console.log('keyup:', evn.type, handler, handler.key);
  }
});

jaywcjlove avatar Mar 21 '19 06:03 jaywcjlove

Use e.repeat That will be true on repeat firings of the event

rakusan2 avatar May 13 '20 20:05 rakusan2