We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello community,
I have a question about the use of a controller. I would like to use the joystick of a ps3 controller to map the mouse movement. I use a pc/windows. I have download the MotioninJoy for the driver and I have mapped the stick, but the movement is not correct. can someone help me, please
this is the code
import procontroll.*;
import java.io.*;
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;
Robot robot;
ControllIO controll;
ControllDevice device;
ControllStick stick;
void setup(){
noFill();
smooth();
frameRate(20);
try {
robot = new Robot();
} catch (AWTException e) {
e.printStackTrace();
}
controll = ControllIO.getInstance(this);
device = controll.getDevice("MotioninJoy Virtual Game Controller");
device.setTolerance(0.05f);
stick = device.getStick(3);
stick.setTolerance(0.05f);
}
void draw(){
x1 +=stick.getY();
y1 +=stick.getX();
robot.mouseMove(x1,y1);
Answers
When posting code into this forum highlight it and press Ctrl+K so that it is formatted for the forum.
stick.getX() and stick.getY() will return a value in the range -1.0 to 1.0 but the variables x1 and y1 are integers so the statement x1 and y1 will rarely change because of rounding the += calculations.
Change x1 and y1 to floats and use
robot.mouseMove(round(x1), round(y1));
That might wotk but proControll is an old library and has some calls to methods deprecated in Processing 2. You might try the Game Control Library (install via Add Library in PDE) library instead.
I used the Game Control Plus library and created this program for an XBOX 360 controller and it worked for me. (You will need to change the device and slider names to suit your device)
hey quark,
thx for your answer, I have download the Game Control Library and have change the device and the sliders, but when I run the sketch I get an error - "illegal component state exception: component must be showing on the screen to determine its location" - I have search in the internet but I didn't find anything, can you help me please.
This exception is thrown when you call
frame.getLocationOnScreen()
before the frame is displayed.I am not saying this will solve the problem but try replacing the last 2 methods with
BTW if a question is aimed at a particular member then put the @ in front of their user-name e.g. @kokagr