react-hotkeys
react-hotkeys copied to clipboard
[BUG] Sequences in keyMap prevent combinations from working
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.
Thanks for the great write-up of this issue, @zjullion.
Does the same problem happen for a key combination that doesn't include alt
?
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.
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+?'