My app changes its state when a person holds modifier keys (Shift, Alt, Ctrl). I track modifier keys using keydown/keyup events:
var altPressed;
window.onkeydown = window.onkeyup = function(e) {
altPressed = e.altKey;
}
Keyboard events don’t trigger outside of the browser tab. Now, imagine the following scenario:
- Hold Shift key
- Click on a link to my app, it will open in a new window
- Release Shift key
keyup
event won’t fire on my page when it isn’t focused so my app will show when I focus on my app’s tab again it will show the Shift key still being pressed.
Would be nice if page visibility events had modifier key properties. Alas, they don’t.
document.addEventListener('webkitvisibilitychange', function(e) {
if (document.webkitHidden) return;
e.altKey // undefined :(
}, false);