I've looked through the API and it seems that the component's getPollData() is what I'm looking for. But I have tested this, and I do not receive changes in poll data when I press buttons or move the axes. I have tried with my mouse and my game controller using the following code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| import java.util.*; import net.java.games.input.*;
public class TestJInput { static Timer t; static Component cp[]; static Controller co; public static void instantiateController(Controller c) { co = c; cp = co.getComponents(); t = new Timer(); t.schedule(new TimerTask() { public void run() { for (Component i : cp) System.out.println(i.getName() + " polls data: " + i.getPollData()); }}, 0, 1000); } public static void main(String[] args) { Controller[] ca = ControllerEnvironment.getDefaultEnvironment().getControllers(); for(int i =0;i<ca.length;i++){ if(ca[i].getName().startsWith("Controller")) { instantiateController(ca[i]); break; } } } } |
It finds the components but the poll data always returns 0.0 no matter what I do with the controller.
Any help would be greatly appreciated. Thanks.