Key gets stuck down in Flash sometimes

Monkey Targets Forums/Flash/Key gets stuck down in Flash sometimes

Grey Alien(Posted 2013) [#1]
Hi all, I made a roguelike where you can hold down a key via KeyDown() to move around and it worked great in GLFW but the Flash version had a problem:

Basically it seemed like the keys (WASD) were "laggy" sometimes and sometimes they would get completely stuck in the down state causing the player to run into a wall forever even though the key was released. Pressing another key seems to break the repeating key problem. The framerate on my game is set to 60 and my FPS counter says it's running at 60 but sometimes when there's a lot going on this drops to 30FPS. Note that it's almost fine with the cursor keys, just rarely they screw up. Very weird indeed.

So my theory is that this is a Flash issue (googling reveals other people reporting similar problems and no fixes with other Flash games). Basically when it gets bogged down with CPU or drawing code it caches a load of keydowns Or maybe it doesn't register key up straight away (or at all).

Pretty annoying. So I had to change the game to force you to tap keys (KeyHit) to move around instead.

By the way I updated Monkey after I read this thread, but it's not this problem: http://www.monkeycoder.co.nz/Community/posts.php?topic=4827

Has anyone else encountered anything similar? Did you figure out a workaround?

Is there anything Monkey could do when a framerate drop is detected to stop taking in keyboard inputs until everything is caught up? In fact what happens now when monkey drops frames? I believe it skips drawing but keeps processing logic, right? Perhaps I should be using some kind of proper timing system instead now?

Any advice/discussion most welcome.


Grey Alien(Posted 2013) [#2]
I managed to greatly optimise the drawing in the game and the framerate is much better but still the key sticking problem with WASD persists. Very strange.


bazmonkey(Posted 2013) [#3]
This bug still exists, as far as I can tell. My latest flash game shows this behavior on Mac/Opera, but not other combinations :/ (tried in monkey 66b and 72b). After 1-2 key presses, the key does not work again. Doesnt seem to affect cursor keys, just other ones, a bit strange.