Fix consuming the remaining input events when mapping the gamepad. See GitHub issue 4 for details.

This commit is contained in:
Cameron Gutman
2013-12-29 19:21:33 -06:00
parent 0bbc25e281
commit df65ac5b45
+9 -11
View File
@@ -306,25 +306,23 @@ public class GamepadConfigFrame extends JFrame {
* Consumes any events left in the queue after the mapping has been made * Consumes any events left in the queue after the mapping has been made
*/ */
private void consumeEvents(final Gamepad pad) { private void consumeEvents(final Gamepad pad) {
// start a new thread to go through all of the remaining events
Thread consumeEvents = new Thread(new Runnable() {
@Override
public void run() {
if (pad.poll()) {
EventQueue queue = pad.getEvents(); EventQueue queue = pad.getEvents();
Event event = new Event(); Event event = new Event();
while (queue.getNextEvent(event)) { for (int i = 0; i < 5; i++) {
if (!pad.poll()) { if (!pad.poll()) {
break; break;
} }
// Drop all events currently in the queue
while (queue.getNextEvent(event) && pad.poll());
// Give the queue a bit of time to fill again
try {
Thread.sleep(50);
} catch (InterruptedException e) {}
} }
} }
}
});
consumeEvents.setName("Consume Events Thread");
consumeEvents.start();
}
/* /*
* Helper method to get the box component that contains the given a mapping * Helper method to get the box component that contains the given a mapping