dmauro / Keypress

A keyboard input capturing utility in which any key can be a modifier key.
http://dmauro.github.io/Keypress/
Apache License 2.0
3.18k stars 313 forks source link

Meta key bug? #78

Closed solcik closed 9 years ago

solcik commented 9 years ago

Hello,

I am starting with Keypress, and so I tried pretty simple thing:

    listener.register_combo({
        "keys": "meta s",
        "prevent_default": true,
        "on_keydown": function () {
            $("input[id*='form-submit']").click();
            console.log('Keypress: meta s');
        }
    });

I was surprised, when I was unable to write letter "S" on the webpage, not even "s", so I added log about being pressed, it is fired correctly, when I press CTRL+S, but does not fire for SHIFT+S (as it should not), but still I am unable to write letters "s" and "S", can you help me or am I doing something wrong?

Chrome 39.0.2171.99 m Windows 7

dmauro commented 9 years ago

You're using the prevent_default property which causes preventDefault() to be called on all constituent events. Since 's' is a part of the 'meta s' combo, it will be prevented since you might be working towards the 'meta s' combo (obviously a little imperfect since the 'meta s' combo is ordered, but that is something I hope to tackle soon). See the documentation on prevent_default:

Any handlers for your combos will event.preventDefault() for the relevant event by default (you can return true in the handler to prevent this). But there is additionally a prevent_default property which will preventDefault() for events of keypresses of all constituent keys of the combo. What this means is that if you have a combo "shift s", both 'shift' and 's' keypresses will independently preventDefault() when pressed.

solcik commented 9 years ago

Sorry for my bad. Thank you for clearing this.