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

[BUG] v2 ignores 'alt+shift(+...)' actions if shift is pressed before alt

Open yched opened this issue 6 years ago โ€ข 0 comments

Describe the bug in 2.0.0, an 'alt+shift' (or any combination containing it : 'alt+shift+q', 'ctrl+alt+shift+q', ...) is not caught if shift is pressed before alt:

<GlobalHotKeys keyMap={{ test: 'shift+alt'}} handlers={{ test: () => console.log('OK') }} />

alt+shift: OK shift+alt: (not caught)

<GlobalHotKeys keyMap={{ test: 'ctrl+alt+shift+q'}} handlers={{ test: () => console.log('OK') }} />

ctrl+alt+shift+q: OK ctrl+shift+alt+q: (not caught) alt+ctrl+shift+q: OK alt+shift+ctrl+q: OK shift+alt+ctrl+q: (not caught) shift+ctrl+alt+q: (not caught)

--> any combination where shift is pressed before alt doesn't seem to be caught

According to the logs below, when the alt key is pressed after shift, it is seen as 'meta', and thus not matched to existing sequences. If I declare the sequence as 'shift+meta' instead, then the results are reversed: alt+shift: (not caught) shift+alt: OK

Expected behavior Any order of key pressed in the combination should trigger the action ? It works in latest 1.x

Platform:

  • Version of react-hotkeys : 2.0.0
  • Browser [e.g. chrome, safari]: Chrome 75
  • OS: Ubuntu 16

Are you willing and able to create a PR request to fix this issue? Not knowledgeable enough

Include the smallest log that includes your issue:

Below is the log for a shift+alt keypress

modules.js?hash=eb50b89f74342a1c286a157bacef7f6e15d5ed50:3293 HotKeys (GLOBAL-E0โค๏ธ-C0๐Ÿ”บ): Registered component:
 {
    "childIds": [],
    "parentId": null,
    "keyMap": {
        "test": "shift+alt"
    }
}
modules.js?hash=eb50b89f74342a1c286a157bacef7f6e15d5ed50:3323 HotKeys (GLOBAL-E0โค๏ธ-C0๐Ÿ”บ): Registered component mount:
 {
    "childIds": [],
    "parentId": null,
    "keyMap": {
        "test": "shift+alt"
    }
}
modules.js?hash=eb50b89f74342a1c286a157bacef7f6e15d5ed50:3774 HotKeys (GLOBAL-C0๐Ÿ”บ): Bound handler handleGlobalKeyDown() to document.onkeydown()
modules.js?hash=eb50b89f74342a1c286a157bacef7f6e15d5ed50:3774 HotKeys (GLOBAL-C0๐Ÿ”บ): Bound handler handleGlobalKeyPress() to document.onkeypress()
modules.js?hash=eb50b89f74342a1c286a157bacef7f6e15d5ed50:3774 HotKeys (GLOBAL-C0๐Ÿ”บ): Bound handler handleGlobalKeyUp() to document.onkeyup()
modules.js?hash=eb50b89f74342a1c286a157bacef7f6e15d5ed50:3684 HotKeys (GLOBAL-C0๐Ÿ”บ): Mounted.
modules.js?hash=eb50b89f74342a1c286a157bacef7f6e15d5ed50:3687 HotKeys (GLOBAL-C0๐Ÿ”บ): Component options: 
 {
    "actions": {
        "test": [
            {
                "prefix": "",
                "actionName": "test",
                "sequenceLength": 1,
                "id": "Alt+Shift",
                "keyDictionary": {
                    "Shift": true,
                    "Alt": true
                },
                "keyEventType": 0,
                "size": 2
            }
        ]
    },
    "handlers": {
        "test": "() => console.log('OK')"
    },
    "componentId": 0,
    "options": {
        "defaultKeyEvent": "keydown"
    }
}
modules.js?hash=eb50b89f74342a1c286a157bacef7f6e15d5ed50:3875 HotKeys (GLOBAL-E1๐Ÿ’š): New 'Shift' keydown event (that has NOT passed through React app).
modules.js?hash=eb50b89f74342a1c286a157bacef7f6e15d5ed50:4068 HotKeys (GLOBAL-E1๐Ÿ’š): Added 'Shift' to current combination: 'Shift'.
modules.js?hash=eb50b89f74342a1c286a157bacef7f6e15d5ed50:4071 HotKeys (GLOBAL-E1๐Ÿ’š): Key history: [
    {
        "keys": {
            "Shift": [
                [
                    0,
                    0,
                    0
                ],
                [
                    1,
                    0,
                    0
                ]
            ]
        },
        "ids": [
            "Shift"
        ],
        "keyAliases": {}
    }
].
modules.js?hash=eb50b89f74342a1c286a157bacef7f6e15d5ed50:4122 HotKeys (GLOBAL-E1๐Ÿ’š): Attempting to find action matching 'Shift' keydown . . .
modules.js?hash=eb50b89f74342a1c286a157bacef7f6e15d5ed50:3423 HotKeys (GLOBAL-E1๐Ÿ’š-C0๐Ÿ”บ): Internal key mapping:
 {
    "": {
        "actionConfigs": {
            "Alt+Shift": {
                "prefix": "",
                "sequenceLength": 1,
                "id": "Alt+Shift",
                "keyDictionary": {
                    "Shift": true,
                    "Alt": true
                },
                "size": 2,
                "events": {
                    "0": {
                        "actionName": "test",
                        "handler": "() => console.log('OK')"
                    }
                }
            }
        },
        "order": null
    }
}
modules.js?hash=eb50b89f74342a1c286a157bacef7f6e15d5ed50:3448 HotKeys (GLOBAL-E1๐Ÿ’š-C0๐Ÿ”บ): No matching actions found for 'Shift' keydown.
modules.js?hash=eb50b89f74342a1c286a157bacef7f6e15d5ed50:3875 HotKeys (GLOBAL-E2๐Ÿ’™): New (simulated) 'Shift' keypress event (that has NOT passed through React app).
modules.js?hash=eb50b89f74342a1c286a157bacef7f6e15d5ed50:4071 HotKeys (GLOBAL-E2๐Ÿ’™): Key history: [
    {
        "keys": {
            "Shift": [
                [
                    1,
                    0,
                    0
                ],
                [
                    1,
                    2,
                    0
                ]
            ]
        },
        "ids": [
            "Shift"
        ],
        "keyAliases": {}
    }
].
modules.js?hash=eb50b89f74342a1c286a157bacef7f6e15d5ed50:4112 HotKeys (GLOBAL-E2๐Ÿ’™): Ignored 'Shift' keypress because it doesn't have any keypress handlers.
modules.js?hash=eb50b89f74342a1c286a157bacef7f6e15d5ed50:3875 HotKeys (GLOBAL-E3๐Ÿ’›): New 'Meta' keydown event (that has NOT passed through React app).
modules.js?hash=eb50b89f74342a1c286a157bacef7f6e15d5ed50:4068 HotKeys (GLOBAL-E3๐Ÿ’›): Added 'Meta' to current combination: 'Meta+Shift'.
modules.js?hash=eb50b89f74342a1c286a157bacef7f6e15d5ed50:4071 HotKeys (GLOBAL-E3๐Ÿ’›): Key history: [
    {
        "keys": {
            "Shift": [
                [
                    1,
                    0,
                    0
                ],
                [
                    1,
                    2,
                    0
                ]
            ],
            "Meta": [
                [
                    0,
                    0,
                    0
                ],
                [
                    1,
                    0,
                    0
                ]
            ]
        },
        "ids": [
            "Meta+Shift"
        ],
        "keyAliases": {}
    }
].
modules.js?hash=eb50b89f74342a1c286a157bacef7f6e15d5ed50:4122 HotKeys (GLOBAL-E3๐Ÿ’›): Attempting to find action matching 'Meta+Shift' keydown . . .
modules.js?hash=eb50b89f74342a1c286a157bacef7f6e15d5ed50:3423 HotKeys (GLOBAL-E3๐Ÿ’›-C0๐Ÿ”บ): Internal key mapping:
 {
    "": {
        "actionConfigs": {
            "Alt+Shift": {
                "prefix": "",
                "sequenceLength": 1,
                "id": "Alt+Shift",
                "keyDictionary": {
                    "Shift": true,
                    "Alt": true
                },
                "size": 2,
                "events": {
                    "0": {
                        "actionName": "test",
                        "handler": "() => console.log('OK')"
                    }
                }
            }
        },
        "order": [
            "Alt+Shift"
        ]
    }
}
modules.js?hash=eb50b89f74342a1c286a157bacef7f6e15d5ed50:3448 HotKeys (GLOBAL-E3๐Ÿ’›-C0๐Ÿ”บ): No matching actions found for 'Meta+Shift' keydown.
modules.js?hash=eb50b89f74342a1c286a157bacef7f6e15d5ed50:3875 HotKeys (GLOBAL-E4๐Ÿ’œ): New (simulated) 'Meta' keypress event (that has NOT passed through React app).
modules.js?hash=eb50b89f74342a1c286a157bacef7f6e15d5ed50:4071 HotKeys (GLOBAL-E4๐Ÿ’œ): Key history: [
    {
        "keys": {
            "Shift": [
                [
                    1,
                    0,
                    0
                ],
                [
                    1,
                    2,
                    0
                ]
            ],
            "Meta": [
                [
                    1,
                    0,
                    0
                ],
                [
                    1,
                    2,
                    0
                ]
            ]
        },
        "ids": [
            "Meta+Shift"
        ],
        "keyAliases": {}
    }
].
modules.js?hash=eb50b89f74342a1c286a157bacef7f6e15d5ed50:4112 HotKeys (GLOBAL-E4๐Ÿ’œ): Ignored 'Meta+Shift' keypress because it doesn't have any keypress handlers.
modules.js?hash=eb50b89f74342a1c286a157bacef7f6e15d5ed50:3875 HotKeys (GLOBAL-E5๐Ÿงก): New 'Meta' keyup event (that has NOT passed through React app).
modules.js?hash=eb50b89f74342a1c286a157bacef7f6e15d5ed50:4071 HotKeys (GLOBAL-E5๐Ÿงก): Key history: [
    {
        "keys": {
            "Shift": [
                [
                    1,
                    0,
                    0
                ],
                [
                    1,
                    2,
                    0
                ]
            ],
            "Meta": [
                [
                    1,
                    2,
                    0
                ],
                [
                    1,
                    2,
                    1
                ]
            ]
        },
        "ids": [
            "Meta+Shift"
        ],
        "keyAliases": {}
    }
].
modules.js?hash=eb50b89f74342a1c286a157bacef7f6e15d5ed50:4112 HotKeys (GLOBAL-E5๐Ÿงก): Ignored 'Meta+Shift' keyup because it doesn't have any keyup handlers.
modules.js?hash=eb50b89f74342a1c286a157bacef7f6e15d5ed50:3875 HotKeys (GLOBAL-E6โค๏ธ): New 'Shift' keyup event (that has NOT passed through React app).
modules.js?hash=eb50b89f74342a1c286a157bacef7f6e15d5ed50:4071 HotKeys (GLOBAL-E6โค๏ธ): Key history: [
    {
        "keys": {
            "Shift": [
                [
                    1,
                    2,
                    0
                ],
                [
                    1,
                    2,
                    1
                ]
            ],
            "Meta": [
                [
                    1,
                    2,
                    0
                ],
                [
                    1,
                    2,
                    1
                ]
            ]
        },
        "ids": [
            "Meta+Shift"
        ],
        "keyAliases": {}
    }
].
modules.js?hash=eb50b89f74342a1c286a157bacef7f6e15d5ed50:4112 HotKeys (GLOBAL-E6โค๏ธ): Ignored 'Meta+Shift' keyup because it doesn't have any keyup handlers.
modules.js?hash=eb50b89f74342a1c286a157bacef7f6e15d5ed50:1726 HotKeys: Window focused - clearing key history

What Configuration options are you using? Nothing apart from

configure({
  logLevel: 'verbose'
})

yched avatar Jul 31 '19 16:07 yched