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

[HELP] How to ignore subsequent keys and use only single key?

Open DudaGod opened this issue 5 years ago • 0 comments

Hello.

I don't understand how to configure HotKeys that it only call handler on one specified key press. Currently my handler calls even if I press subsequent keys.

Example:

import {GlobalHotKeys} from 'react-hotkeys';

const keyMap = {
  PREV_SCREENSHOT: 'down'
};
const handlers = {
  PREV_SCREENSHOT: () => console.log('called');
};

<GlobalHotKeys keyMap={keyMap} handlers={handlers} />

And the problem that if I press cmd+down (cmd pressed and don't released until down is not pressed too) then my handler is called. I try to use ignoreEventsCondition configure function and IgnoreKeys component but they do not help me to fix it.

So I had to explicitly set stub for cmd+down, like this:

const keyMap = {
  PREV_SCREENSHOT: 'down',
  IGNORE_CMD_DOWN: 'cmd+down'
};
const handlers = {
  PREV_SCREENSHOT: () => console.log('called'),
  IGNORE_CMD_DOWN: () => {}
};

Thank you.

DudaGod avatar Sep 15 '20 13:09 DudaGod