Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
yched opened this issue Jul 31, 2019 · 0 comments
Open

Comments

@yched
Copy link
Contributor

yched commented Jul 31, 2019

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'
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant