reset modifiers to false on window focus. fixes alt+tab, tab switching, and related issues #32

Merged
merged 1 commit into from Nov 11, 2011

2 participants

@lowe

proposed fix for issue #16, including these example problems:

  • when I alt+tab away from the browser to another application, the window doesn't get the keyup events, so _mods[alt] stays true after I navigate back. to reproduce:

key('d', function () {
console.log('pressed d!');
});

alt+tab to another program.
navigate back to the browser.
press 'd', nothing happens.

  • same issue when I use shift+command+] to switch browser tabs on mac (or any other tab-switching shortcut that involves modifiers).

  • here's a sweet one :) same issue when i do:

key('ctrl+c', function () {
alert('pressed ctrl+c!');
}) ;

alert() takes focus away from the window, so after i click 'ok', alert() will keep getting called every time I press 'c' without the modifier.

fix:

reset _mod values to false every time the window is focused. i experimented with document vs window, and focus vs blur, and window focus is the only event that works for every scenario. tested on Chrome/FF/Safari.

@lowe lowe reset modifiers to false on window focus. fixes issues with alt+tab, …
…switching browser tabs with the keyboard, etc
b8e03be
@madrobby madrobby merged commit e9c78d3 into madrobby:master Nov 11, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment