The definition of "pressed" vs. "held" is up to you. Many programs even let you configure it. You would have to start some sort of timer when a key was first pressed. If the key is released before the timer completes, you cancel it because the key was only "pressed". If the timer completes, the key was "held". You can use java.util.Timer
and java.util.TimerTask
for this.
How do I detect if a key is held down in Java 2d?
Domanda
I'm curious if I can tell if a key is being HELD, not pressed and let go.
I need to know this because I'm going to play a shorter mp3 file if it is just pressed and a longer one if it is held.
Thanks in advance!
(I know I asked this for libgdx but I need to know for Java 2d now)
Soluzione
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow