Button and HAT presses in JInput is based on events, meaning if I press Button 1, it will only fire once while I'm holding it down and once again when I release the button. I want to make it so that if I have the button held down, it will still keep calling the method I assigned to it. How do I do this>
Asked
Active
Viewed 315 times
0
-
If you have control over the main loop, set up a flag that when true, will call you method. If you don't set up a timer that can be triggered on a regular basis until you release the button – MadProgrammer Nov 17 '13 at 23:17
-
Can you give an example? I'm kinda new to Java itself. – Propeller Nov 17 '13 at 23:20
-
It would depend on how you've setup you code? Are you using a main loop of some kind or not? – MadProgrammer Nov 17 '13 at 23:21
-
No, I don't. I'm kinda interested in the timer approach. – Propeller Nov 17 '13 at 23:21
1 Answers
0
Okay so I did some research and eventually ended up with the following which solved it for me:
myTimer = new Timer();
myTimer.schedule(new TimerTask() {
@Override
public void run() {
// Do stuff
}
}, 50, 50);
Then I call the following on another method when I need to stop the timer.
myTimer.cancel;
myTimer.purge;

Propeller
- 2,465
- 6
- 35
- 49