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

[BUG] Sequences in keyMap prevent combinations from working

Open zjullion opened this issue 5 years ago โ€ข 3 comments

Describe the bug When adding a sequence to your keyMap (such as 'up up down down left right left right a b'), combinations (such as 'ctrl+alt+t') no longer work correctly - they will sometimes trigger the first time the key combination is pressed, but not the second time.

Once the window loses focus, and KeyEventManager._clearKeyHistory() https://github.com/greena13/react-hotkeys/blob/80a13fbf09fca9fbd79b2b6de24b05e00e8f13e7/src/lib/KeyEventManager.js#L110 runs, the combination will again work just one time and then stop working until KeyEventManager._clearKeyHistory() runs again.

It's worth noting that the sequence ('up up down down left right left right a b') works correctly throughout.

How are you using react hotkeys components? (HotKeys, GlobalHotKeys, IgnoreKeys etc) Using a <GlobalHotKeys> right now, but this bug also occurs with <HotKeys>

Example code:

configure({
  ignoreTags: [],
  logLevel: 'verbose'
})
const hotKeyMap = {
  openSearchDialog: 'ctrl+alt+t',
  konami: 'up up down down left right left right a b'
}

...

render () {
    return (
      <SomeComponent>
        <GlobalHotKeys
          keyMap={hotKeyMap}
          handlers={{
            openSearchDialog: () => console.log('openSearchDialog'),
            konami: () => console.log('konami')
          }}
          allowChanges
      </SomeComponent>
    )
  }

Expected behavior I expect that sequences and combinations can both be used without interfering with each other.

Platform (please complete the following information):

  • Version of react-hotkeys 2.0.0
  • Browser tested in chrome and firefox
  • OS: macOS High Sierra

Are you willing and able to create a PR request to fix this issue? Probably not, sorry. We aren't actually using key sequences in our application right now, just combinations

Include the smallest log that includes your issue:

The 'small' log generated with verbose is 3000 lines long, so here's a log with debug instead:

HotKeys (GLOBAL-E1๐Ÿ’š): New 'Control' keydown event (that has NOT passed through React app).
AbstractKeyEventStrategy.js:475 HotKeys (GLOBAL-E1๐Ÿ’š-C0๐Ÿ”บ): No matching actions found for 'Control' keydown.
GlobalKeyEventStrategy.js:403 HotKeys (GLOBAL-E2๐Ÿ’™): New (simulated) 'Control' keypress event (that has NOT passed through React app).
GlobalKeyEventStrategy.js:640 HotKeys (GLOBAL-E2๐Ÿ’™): Ignored 'Control' keypress because it doesn't have any keypress handlers.
GlobalKeyEventStrategy.js:403 HotKeys (GLOBAL-E3๐Ÿ’›): New 'Alt' keydown event (that has NOT passed through React app).
AbstractKeyEventStrategy.js:475 HotKeys (GLOBAL-E3๐Ÿ’›-C0๐Ÿ”บ): No matching actions found for 'Alt+Control' keydown.
GlobalKeyEventStrategy.js:403 HotKeys (GLOBAL-E4๐Ÿ’œ): New (simulated) 'Alt' keypress event (that has NOT passed through React app).
GlobalKeyEventStrategy.js:640 HotKeys (GLOBAL-E4๐Ÿ’œ): Ignored 'Alt+Control' keypress because it doesn't have any keypress handlers.
GlobalKeyEventStrategy.js:403 HotKeys (GLOBAL-E5๐Ÿงก): New 'โ€ ' keydown event (that has NOT passed through React app).
AbstractKeyEventStrategy.js:464 HotKeys (GLOBAL-E5๐Ÿงก-C0๐Ÿ”บ): Found action that matches 'Alt+Control+โ€ ': itemSearch. Calling handler . . .
App.js:62 openSearchDialog // Search dialog correctly opens the first time
GlobalKeyEventStrategy.js:254 HotKeys (GLOBAL-C0๐Ÿ”บ): Global component 0 updated.
GlobalKeyEventStrategy.js:671 HotKeys (GLOBAL-E5๐Ÿงก-C0๐Ÿ”บ): Stopping further event propagation.
GlobalKeyEventStrategy.js:663 HotKeys (GLOBAL-E5๐Ÿงก): Searching no further, as handler has been found (and called).
GlobalKeyEventStrategy.js:403 HotKeys (GLOBAL-E6โค๏ธ): New 'โ€ ' keypress event (that has NOT passed through React app).
GlobalKeyEventStrategy.js:640 HotKeys (GLOBAL-E6โค๏ธ): Ignored 'Alt+Control+โ€ ' keypress because it doesn't have any keypress handlers.
GlobalKeyEventStrategy.js:403 HotKeys (GLOBAL-E7๐Ÿ’š): New 'โ€ ' keyup event (that has NOT passed through React app).
GlobalKeyEventStrategy.js:640 HotKeys (GLOBAL-E7๐Ÿ’š): Ignored 'Alt+Control+โ€ ' keyup because it doesn't have any keyup handlers.
GlobalKeyEventStrategy.js:403 HotKeys (GLOBAL-E8๐Ÿ’™): New 'Control' keyup event (that has NOT passed through React app).
GlobalKeyEventStrategy.js:640 HotKeys (GLOBAL-E8๐Ÿ’™): Ignored 'Alt+Control+โ€ ' keyup because it doesn't have any keyup handlers.
GlobalKeyEventStrategy.js:403 HotKeys (GLOBAL-E9๐Ÿ’›): New 'Alt' keyup event (that has NOT passed through React app).
GlobalKeyEventStrategy.js:640 HotKeys (GLOBAL-E9๐Ÿ’›): Ignored 'Alt+Control+โ€ ' keyup because it doesn't have any keyup handlers.
GlobalKeyEventStrategy.js:403 HotKeys (GLOBAL-E10๐Ÿ’œ): New 'Control' keydown event (that has NOT passed through React app).
AbstractKeyEventStrategy.js:475 HotKeys (GLOBAL-E10๐Ÿ’œ-C0๐Ÿ”บ): No matching actions found for 'Control' keydown.
GlobalKeyEventStrategy.js:403 HotKeys (GLOBAL-E11๐Ÿงก): New (simulated) 'Control' keypress event (that has NOT passed through React app).
GlobalKeyEventStrategy.js:640 HotKeys (GLOBAL-E11๐Ÿงก): Ignored 'Control' keypress because it doesn't have any keypress handlers.
GlobalKeyEventStrategy.js:403 HotKeys (GLOBAL-E12โค๏ธ): New 'Alt' keydown event (that has NOT passed through React app).
AbstractKeyEventStrategy.js:475 HotKeys (GLOBAL-E12โค๏ธ-C0๐Ÿ”บ): No matching actions found for 'Alt+Control' keydown.
GlobalKeyEventStrategy.js:403 HotKeys (GLOBAL-E13๐Ÿ’š): New (simulated) 'Alt' keypress event (that has NOT passed through React app).
GlobalKeyEventStrategy.js:640 HotKeys (GLOBAL-E13๐Ÿ’š): Ignored 'Alt+Control' keypress because it doesn't have any keypress handlers.
GlobalKeyEventStrategy.js:403 HotKeys (GLOBAL-E14๐Ÿ’™): New 'โ€ ' keydown event (that has NOT passed through React app).
AbstractKeyEventStrategy.js:475 HotKeys (GLOBAL-E14๐Ÿ’™-C0๐Ÿ”บ): No matching actions found for 'Alt+Control+โ€ ' keydown. // This is a bug - an action should have been found for this combination
GlobalKeyEventStrategy.js:403 HotKeys (GLOBAL-E15๐Ÿ’›): New 'โ€ ' keypress event (that has NOT passed through React app).
GlobalKeyEventStrategy.js:640 HotKeys (GLOBAL-E15๐Ÿ’›): Ignored 'Alt+Control+โ€ ' keypress because it doesn't have any keypress handlers.
GlobalKeyEventStrategy.js:403 HotKeys (GLOBAL-E16๐Ÿ’œ): New 'โ€ ' keyup event (that has NOT passed through React app).
GlobalKeyEventStrategy.js:640 HotKeys (GLOBAL-E16๐Ÿ’œ): Ignored 'Alt+Control+โ€ ' keyup because it doesn't have any keyup handlers.
GlobalKeyEventStrategy.js:403 HotKeys (GLOBAL-E17๐Ÿงก): New 'Control' keyup event (that has NOT passed through React app).
GlobalKeyEventStrategy.js:640 HotKeys (GLOBAL-E17๐Ÿงก): Ignored 'Alt+Control+โ€ ' keyup because it doesn't have any keyup handlers.
GlobalKeyEventStrategy.js:403 HotKeys (GLOBAL-E18โค๏ธ): New 'Alt' keyup event (that has NOT passed through React app).
GlobalKeyEventStrategy.js:640 HotKeys (GLOBAL-E18โค๏ธ): Ignored 'Alt+Control+โ€ ' keyup because it doesn't have any keyup handlers.
KeyEventManager.js:183 HotKeys: Window focused - clearing key history \\ KeyEventManager._clearKeyHistory() is called
GlobalKeyEventStrategy.js:403 HotKeys (GLOBAL-E19๐Ÿ’š): New 'Control' keydown event (that has NOT passed through React app).
AbstractKeyEventStrategy.js:475 HotKeys (GLOBAL-E19๐Ÿ’š-C0๐Ÿ”บ): No matching actions found for 'Control' keydown.
GlobalKeyEventStrategy.js:403 HotKeys (GLOBAL-E20๐Ÿ’™): New (simulated) 'Control' keypress event (that has NOT passed through React app).
GlobalKeyEventStrategy.js:640 HotKeys (GLOBAL-E20๐Ÿ’™): Ignored 'Control' keypress because it doesn't have any keypress handlers.
GlobalKeyEventStrategy.js:403 HotKeys (GLOBAL-E21๐Ÿ’›): New 'Alt' keydown event (that has NOT passed through React app).
AbstractKeyEventStrategy.js:475 HotKeys (GLOBAL-E21๐Ÿ’›-C0๐Ÿ”บ): No matching actions found for 'Alt+Control' keydown.
GlobalKeyEventStrategy.js:403 HotKeys (GLOBAL-E22๐Ÿ’œ): New (simulated) 'Alt' keypress event (that has NOT passed through React app).
GlobalKeyEventStrategy.js:640 HotKeys (GLOBAL-E22๐Ÿ’œ): Ignored 'Alt+Control' keypress because it doesn't have any keypress handlers.
GlobalKeyEventStrategy.js:403 HotKeys (GLOBAL-E23๐Ÿงก): New 'โ€ ' keydown event (that has NOT passed through React app).
AbstractKeyEventStrategy.js:464 HotKeys (GLOBAL-E23๐Ÿงก-C0๐Ÿ”บ): Found action that matches 'Alt+Control+โ€ ': itemSearch. Calling handler . . .
App.js:62 openSearchDialog // Search dialog correctly opens again after clearing the key history
GlobalKeyEventStrategy.js:254 HotKeys (GLOBAL-C0๐Ÿ”บ): Global component 0 updated.
GlobalKeyEventStrategy.js:671 HotKeys (GLOBAL-E23๐Ÿงก-C0๐Ÿ”บ): Stopping further event propagation.
GlobalKeyEventStrategy.js:663 HotKeys (GLOBAL-E23๐Ÿงก): Searching no further, as handler has been found (and called).
GlobalKeyEventStrategy.js:403 HotKeys (GLOBAL-E24โค๏ธ): New 'โ€ ' keypress event (that has NOT passed through React app).
GlobalKeyEventStrategy.js:640 HotKeys (GLOBAL-E24โค๏ธ): Ignored 'Alt+Control+โ€ ' keypress because it doesn't have any keypress handlers.
GlobalKeyEventStrategy.js:403 HotKeys (GLOBAL-E25๐Ÿ’š): New 'โ€ ' keyup event (that has NOT passed through React app).
GlobalKeyEventStrategy.js:640 HotKeys (GLOBAL-E25๐Ÿ’š): Ignored 'Alt+Control+โ€ ' keyup because it doesn't have any keyup handlers.
GlobalKeyEventStrategy.js:403 HotKeys (GLOBAL-E26๐Ÿ’™): New 'Control' keyup event (that has NOT passed through React app).
GlobalKeyEventStrategy.js:640 HotKeys (GLOBAL-E26๐Ÿ’™): Ignored 'Alt+Control+โ€ ' keyup because it doesn't have any keyup handlers.
GlobalKeyEventStrategy.js:403 HotKeys (GLOBAL-E27๐Ÿ’›): New 'Alt' keyup event (that has NOT passed through React app).
GlobalKeyEventStrategy.js:640 HotKeys (GLOBAL-E27๐Ÿ’›): Ignored 'Alt+Control+โ€ ' keyup because it doesn't have any keyup handlers.
GlobalKeyEventStrategy.js:403 HotKeys (GLOBAL-E28๐Ÿ’œ): New 'Control' keydown event (that has NOT passed through React app).
AbstractKeyEventStrategy.js:475 HotKeys (GLOBAL-E28๐Ÿ’œ-C0๐Ÿ”บ): No matching actions found for 'Control' keydown.
GlobalKeyEventStrategy.js:403 HotKeys (GLOBAL-E29๐Ÿงก): New (simulated) 'Control' keypress event (that has NOT passed through React app).
GlobalKeyEventStrategy.js:640 HotKeys (GLOBAL-E29๐Ÿงก): Ignored 'Control' keypress because it doesn't have any keypress handlers.
GlobalKeyEventStrategy.js:403 HotKeys (GLOBAL-E30โค๏ธ): New 'Alt' keydown event (that has NOT passed through React app).
AbstractKeyEventStrategy.js:475 HotKeys (GLOBAL-E30โค๏ธ-C0๐Ÿ”บ): No matching actions found for 'Alt+Control' keydown.
GlobalKeyEventStrategy.js:403 HotKeys (GLOBAL-E31๐Ÿ’š): New (simulated) 'Alt' keypress event (that has NOT passed through React app).
GlobalKeyEventStrategy.js:640 HotKeys (GLOBAL-E31๐Ÿ’š): Ignored 'Alt+Control' keypress because it doesn't have any keypress handlers.
GlobalKeyEventStrategy.js:403 HotKeys (GLOBAL-E32๐Ÿ’™): New 'โ€ ' keydown event (that has NOT passed through React app).
AbstractKeyEventStrategy.js:475 HotKeys (GLOBAL-E32๐Ÿ’™-C0๐Ÿ”บ): No matching actions found for 'Alt+Control+โ€ ' keydown. // This is a bug - an action should have been found for this combination
GlobalKeyEventStrategy.js:403 HotKeys (GLOBAL-E33๐Ÿ’›): New 'โ€ ' keypress event (that has NOT passed through React app).
GlobalKeyEventStrategy.js:640 HotKeys (GLOBAL-E33๐Ÿ’›): Ignored 'Alt+Control+โ€ ' keypress because it doesn't have any keypress handlers.
GlobalKeyEventStrategy.js:403 HotKeys (GLOBAL-E34๐Ÿ’œ): New 'โ€ ' keyup event (that has NOT passed through React app).
GlobalKeyEventStrategy.js:640 HotKeys (GLOBAL-E34๐Ÿ’œ): Ignored 'Alt+Control+โ€ ' keyup because it doesn't have any keyup handlers.
GlobalKeyEventStrategy.js:403 HotKeys (GLOBAL-E35๐Ÿงก): New 'Control' keyup event (that has NOT passed through React app).
GlobalKeyEventStrategy.js:640 HotKeys (GLOBAL-E35๐Ÿงก): Ignored 'Alt+Control+โ€ ' keyup because it doesn't have any keyup handlers.
GlobalKeyEventStrategy.js:403 HotKeys (GLOBAL-E36โค๏ธ): New 'Alt' keyup event (that has NOT passed through React app).
GlobalKeyEventStrategy.js:640 HotKeys (GLOBAL-E36โค๏ธ): Ignored 'Alt+Control+โ€ ' keyup because it doesn't have any keyup handlers.
KeyEventManager.js:183 HotKeys: Window focused - clearing key history

What Configuration options are you using?

configure({
  ignoreTags: [],
  logLevel: 'verbose'
})

However, it's worth noting that in chrome I've tested both with and without ignoreTags, and the error exists in both cases.

zjullion avatar Sep 13 '19 17:09 zjullion

Thanks for the great write-up of this issue, @zjullion.

Does the same problem happen for a key combination that doesn't include alt?

greena13 avatar Oct 20 '19 13:10 greena13

Thanks for replying - it seems to affect all key combinations, not just combinations that include alt. I tried with both a+s+d+f and shift+k - both work fine when no sequence is present, but fail when I add the konami code.

zjullion avatar Oct 23 '19 22:10 zjullion

Hi there!

We are having same situation here.

We would like to bind hotkeys a then <1-5> but when I pass it as sequence: 'a 1' most of our hotkey handlers will stop working after first execution.

Here are the keyMap definitions:

export const SHOW_HOTKEY_INFO = {
  name: 'SHOW_HOTKEY_INFO',
  group: 'general',
  sequence: 'shift+?',
};

export const CREATE_NEW_MAIL = {
  name: 'CREATE_NEW_MAIL',
  group: 'general',
  sequence: 'c',
};
export const CREATE_NEW_NOTE = {
  name: 'CREATE_NEW_NOTE',
  group: 'general',
  sequence: 'v',
};
export const CREATE_NEW_TASKLIST = {
  name: 'CREATE_NEW_TASKLIST',
  group: 'general',
  sequence: 'b',
};

export const OPEN_APP_CALENDAR = {
  name: 'APP_SWITCH_CALENDAR',
  group: 'applications',
  sequence: 'a 2',
};
export const OPEN_APP_CONTACTS = {
  name: 'APP_SWITCH_CONTACTS',
  group: 'applications',
  sequence: 'a 3',
};
export const OPEN_APP_STORAGE = {
  name: 'APP_SWITCH_STORAGE',
  group: 'applications',
  sequence: 'a 4',
};
export const OPEN_APP_CONSOLE = {
  name: 'APP_SWITCH_CONSOLE',
  group: 'applications',
  sequence: 'a 5',
};

Also worth noting that mapping on the '?' sequence is not working only if you pass as 'shift+?'

dannystyleart avatar Nov 14 '19 15:11 dannystyleart