I have an interface that needs to react to ‘long key presses’. That means 2 different actions for the same key based on how long the key has been down:
PRESS LEFT CURSOR: action A
PRESS & HOLD LEFT CURSOR: action B
Well, it’s proving harder that I thought. The main problem is that both Keyboard.KEY-DOWN and Keyboard.KEY-UP fire continuously if you hold the key down. This looks weird to me although might make sense if you think about imputing text (if you are entering text and hold down a key it starts to fill the space).
When I was trying to tackle the problem I thought about starting a counter on the KEY-DOWN and resetting it on KEY-UP. Then if it reached certain threshold fire an event. The problem is the counter resets straight away because they KEY-UP event fires all the time.
I’m aware of the keyboard polling classes such as BigRoom‘s and Senocular‘s but they don’t solve the problem because they base their status on the same events.
I could go for timers starting a timer on KEY-DOWN and after x milliseconds check if the key is still down but that would assume that the key has been down all the time. I don’t think it would be reliable.
And this is the point I’m starting to run out of ideas. Is there a much simpler method I’ve overlooked? I hope there is!
Thanks,
Juan
Sorry that took me so long to come back, but was on the middle of the project and really didn’t have time to look deeper into this. Now I have and I’ve found that there’s no such problem. Read below for the long answer.
This is only hapenning under very specific circumstances and probably none to blame Adobe.
I have an iMac running Ubuntu and develop Flash on a virtual machine running Windows XP. This problem only appears on the virtual XP, the same application running natively on Ubuntu (and probably other systems) doesn’t show the problem.
And because I have some other keyboard quirks when using the VM, I think the problem is on VirtualBox’s keyboard driver.
Thanks to everybody that took the time to look into this. I hope this helps for other people!
Juan