I'm developing an HTML5 canvas game, and I listen for key down/up like this:
window.addEventListener('keyup', function(event) {
// handle
});
window.addEventListener('keydown', function(event) {
// handle
});
This works fine for me on my Macbook Pro on Safari, Chrome, and Firefox.
However, a lot of my users are reporting having "sticky keys" -- they'll press a key to start moving upwards and later release that key, but the 'keyup' event won't be received and they'll be stuck continuously moving upwards until they press and release the up key again to trigger another "keyup" event.
Does anyone have any idea why this might be happening?
Things I've done already:
Reset all keys if the window loses focus using an event listener on the window object for the "blur" event. If the user switches tabs momentarily or the window somehow loses focuses otherwise, all keys will receive a keyup event and all movement in the game will stop.
Disable right click on the canvas using oncontextmenu='return false;'. I found that right clicking and bringing up the context menu would cause this bug to happen. It's the only reliable way I've found to reproduce it -- I'm really lost as to why so many users are seeing this bug even with right clicking disabled.