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

bug: registration of keys failed #91

Open Hallasdor opened 9 years ago

Hallasdor commented 9 years ago

Button keep being in 'pressed' state after surtain combinations. This happens if you perform the following actions: 1] press and hold shift button 2] press and hold any of the 'num0', 'num1', 'num2', 'num3', 'num4', 'num5', 'num6', 'num7', 'num8', 'num9', 'num.' buttons 3] release the shift button 4] release the button pressed in [2]

The reason for this seems to be that these numpad buttons have a completely different button registration when pressing the shift button. As soon as you release the shift button, the release function registrates a different button for the release state.

This bug can be repeated everytime if you follow the 4 steps.

It is probably impossible to register the correct buttons (I'm assuming the browser registers the 'wrong' button), so maybe you should (also) register the numpad buttons in these specific scenario's

Hallasdor commented 9 years ago

I have created a (dirty) fix for this problem. Hopefully this will help others in the future.

Listener.prototype._key_down = function (key, e) { // line 451

function checkForCounterpart(key, list) {
    if (list.length > 0) {
        var index = list.indexOf(key);
        if (index > -1) {
            list.splice(index, 1);
        }
    }
};

switch (key) {
    case "num_decimal":
        checkForCounterpart("delete", this._keys_down);
        break;
    case "num_0":
        checkForCounterpart("insert", this._keys_down);
        break;
    case "num_1":
        checkForCounterpart("end", this._keys_down);
        break;
    case "num_2":
        checkForCounterpart("down", this._keys_down);
        break;
    case "num_3":
        checkForCounterpart("pagedown", this._keys_down);
        break;
    case "num_4":
        checkForCounterpart("left", this._keys_down);
        break;
    case "num_5":
        checkForCounterpart("num", this._keys_down);
        break;
    case "num_6":
        checkForCounterpart("right", this._keys_down);
        break;
    case "num_7":
        checkForCounterpart("home", this._keys_down);
        break;
    case "num_8":
        checkForCounterpart("up", this._keys_down);
        break;
    case "num_9":
        checkForCounterpart("pageup", this._keys_down);
        break;
}
... //the original code

}

dmauro commented 9 years ago

What browser/OS combo are you seeing this with? Are any other supported keys doing this? I can't reproduce it on OS X + Chrome.