I am attempting to print out the mouse location using Jinput:
public static void main(String[] args) {
input = new InputManager();
while (true) {
for (Mouse mouse : input.getMice()) {
mouse.poll();
System.out.println("Mouse X: " + mouse.getX().getPollData());
System.out.println("Mouse Y: " + mouse.getY().getPollData());
System.out.println("---------");
}
try {
Thread.sleep(100);
} catch (Exception e) {
// DO NOTHING < BAD
}
}
}
Here is my InputManager, which upon initialization scans for all the input devices, and separates all the mice into a separate list:
public class InputManager {
public ArrayList<Mouse> mice;
public InputManager() {
mice = new ArrayList<Mouse>();
Controller[] inputs = ControllerEnvironment.getDefaultEnvironment()
.getControllers();
for (int i = 0; i < inputs.length; i++) {
Mouse mouse;
if (inputs[i].getType() == Controller.Type.MOUSE) {
mouse = (Mouse) inputs[i];
mice.add(mouse);
}
}
System.out.println("Discovered " + mice.size() + " mice.");
}
public ArrayList<Mouse> getMice() {
return mice;
}
}
The information that is being printed out is always 0 for both x and y. I am running this on windows 10, does that cause any issues? How do I get the mouse data from the mouse using Jinput?