kristian / system-hook

Global Keyboard / Mouse Hook for Java applications.
MIT License
269 stars 48 forks source link

Intended behavior on keys being held down #21

Closed TheNotary closed 6 years ago

TheNotary commented 6 years ago

So when I hold a key down, the KeyDown event seems to be firing many many times. Is that the intended behavior because if memory serves, the keydown and keyup should only fire once, when the transition from up to down occurs.

In other words, when I hold the 'a' key down for a few seconds and then let it up for the same amount of time, I see the below in the console for the demo:

65 [down]
65 [down]
65 [down]
65 [down]
65 [down]
65 [down]
65 [down]
65 [down]
65 [down]
65 [up]

This is happening on a windows 7 machine that's been compiled via mvn install and including this project as a dependency.

kristian commented 6 years ago

Mhm, yes sounds reasonable to treat differently. I will take a look at it this weekend. Thanks.

kristian commented 6 years ago

Sorry that it took so long to respond to this. Generally I decided to stay compliant to Javas KeyEvent. Also for the key event (pressed & typed) are fired repeatedly if the key is held down on the keyboard. Performancewise it will not make much of a difference. The event will be captured in any case.

For your use case, you could still go ahead and add a simple boolish condition to your key listener, in order to track only one "down" event per key press. Hope this helps. Thanks for your suggestion tough! =)