increpare / PuzzleScript

Open Source HTML5 Puzzle Game Engine
MIT License
903 stars 159 forks source link

Keys get "stuck" when alt-tabbing #38

Closed salty-horse closed 10 years ago

salty-horse commented 10 years ago

If I start a PuzzleScript game and hold an arrow key and alt-tab to a different window, depress the key, then alt-tab back, PuzzleScript thinks the key is still pressed.

It will keep triggering events until you press the arrow again, so PuzzleScript receives the "keyup". Unfortunately that doesn't always work.

I've tested this with Firefox and Chrome on several games, e.g. http://www.puzzlescript.net/play.html?p=6851495 (Just start the game and press the right arrow)

roryokane commented 10 years ago

Similarly, the W key gets stuck when I hit Command-W to close the tab in Firefox on Mac OS X. Not only does the tab not close, but also W (up) is continuously sent to the game until I press and release W again.

increpare commented 10 years ago

Thanks for reporting this!

On Fri, Jan 10, 2014 at 11:02 PM, Rory O’Kane notifications@github.comwrote:

Similarly, the W key gets stuck when I hit Command-W to close the tab in Firefox on Mac OS X. Not only does the tab not close, but also W (up) is continuously sent to the game until I press and release W again.

— Reply to this email directly or view it on GitHubhttps://github.com/increpare/PuzzleScript/issues/38#issuecomment-32075704 .

increpare commented 10 years ago

uh, this is moderately gross. if someone else wants to propose a fix for this, or explain to me how to fix it, I'm all ears. i guess reset all input when focus is regained, just don't know what handlers to attach to what. (the input code is in inputoutput.js). I already have an onkeyup action, which should tell you how to release keys.

Draknek commented 10 years ago

This should do it: https://github.com/Draknek/PuzzleScript/commit/7bc076b63ef171d97a4131f84fef9356fd69423e

increpare commented 10 years ago

alan, amazing. thanks so much. fixed.

roryokane commented 10 years ago

This bug still exists in Chrome for Mac. If I open that game, hold right arrow, Ctrl-Tab to switch tabs, then switch back, then the key is stuck and the character keeps moving right until I hit right arrow again. However, the bug is now fixed in Firefox for Mac – the character is not moving when I switch back to the tab in Firefox.

Also, the problem with Command-W to close the tab not working still exists in Firefox for Mac. But it seems like it doesn’t happen in Chrome for Mac. I’ve created a separate issue for that, #51.

increpare commented 10 years ago

I think I've fixed this now - if you could check again for me, it'd be super super.

roryokane commented 10 years ago

Yep, it’s fixed – the problem does not happen in Firefox 27, Chrome, or Safari 5.1 on my OS X 10.6 computer.

increpare commented 10 years ago

Thanks for letting me know! :)