I had a curious problem today: A script, that always worked before, stopped to work because apparently 'keyup' was fired directly after every 'keydown' event, killing some events that waited for long keypresses.
After testing around, I found out that my synergy was responsible for that.
Finally, I found a solution to the problem: A jQuery extension that allowed me to delay (and collect) certain events, namely http://benalman.com/projects/jquery-throttle-debounce-plugin/
$(window).keyup( $.debounce(100, onKeyUp) )
This worked for a bit, until I noticed another problem: Multiple keys at once. Let's say, you press the 'up' button, and the 'left' button - and then let go of both at the same time. the $.debounce() will handle both as the same keyup event, letting the event only fire once and causing event.keyCode
to only contain one key instead of both.
The simplest solution would be, to check all the keys pressed when the keyup event is fired, not relying on event.keyCode
since it's incomplete in this case.
My problem is: how can I find out what other keys are still pressed, whitout relying on keydown / keyup events? (since they wont work, because of synergy)
function onKeyUp(event) {
// get all keys pressed
}
Is there some kind of window
variable keeping track of the keys?
Any ideas?