1

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?

Katai
  • 2,773
  • 3
  • 31
  • 45
  • Could you please explain _what_ you're trying to do (from the start)? – Dogbert May 16 '13 at 11:54
  • I want to get a list of all keys currently pressed (and held down) by the user, whitout relying on keyup / keydown events. – Katai May 16 '13 at 11:56
  • And what do you mean by `my synergy was responsible for that`? – Dogbert May 16 '13 at 11:57
  • synergy allows one to share the same keyboard / mouse between two computers. Apparently, this seems to cause some problems with keydown / keyup events (after _every_ keydown event, a keyup event is fired, even if you didnt let go of the key yet) - this causes some issues if you're trying to do something _while_ the user is pressing a key – Katai May 16 '13 at 11:59
  • Your question looks very similar to one of my own questions (which already has an answer): http://stackoverflow.com/questions/13640061/get-a-list-of-all-currently-pressed-keys-in-javascript – Anderson Green Jun 11 '13 at 05:56
  • Anderson Green - that question has an answer which uses keyup/keydown, so definitely not relevant. – DAG Aug 21 '17 at 20:25

0 Answers0