kwhat / jnativehook

Global keyboard and mouse listeners for Java.
Other
1.74k stars 347 forks source link

How to prevent the keyPressed event from continuously firing when a key is held down without being released? #470

Open formatsystem opened 2 months ago

formatsystem commented 2 months ago

Hello. My idea is that after pressing the specified key, KeyPressed should only be executed once without releasing the key, instead of continuously executing nativeKeyPressed in a loop while the key is held down. How can I improve this?

kwhat commented 2 months ago

It's called key bounce and it was an internal design feature. The rate at which the key bounces should be the value of the jnativehook.key.repeat.rate property and the delay until the bounce starts is the jnativehook.key.repeat.delay. If you don't want or need the repeat, set a flag where you are listening for events and ignore the subsequent key press events. What type of flag depends on how you want the ignore to work.

formatsystem commented 2 months ago

It's called key bounce and it was an internal design feature. The rate at which the key bounces should be the value of the jnativehook.key.repeat.rate property and the delay until the bounce starts is the jnativehook.key.repeat.delay. If you don't want or need the repeat, set a flag where you are listening for events and ignore the subsequent key press events. What type of flag depends on how you want the ignore to work.

Thanks for your help.