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