0

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.

Victor Zhou
  • 423
  • 3
  • 14
  • Im not sure if anyone will really be able to help you much with only that info. I know it's hard, but is it not possible for you to give a little more info/small scenary where we can reproduce that? – Mayday Jul 18 '16 at 18:39
  • See http://stackoverflow.com/questions/11225694/why-are-onkeyup-events-not-firing-in-javascript-game, it's basically the same issue. Does anyone know if the accepted answer there is still relevant? It seems weird that a keydown event could be fired after the keyup event... maybe I can't reproduce this issue because my computer is relatively new and has ample CPU power? – Victor Zhou Jul 18 '16 at 18:50

0 Answers0