PLOrk fall2008/BasicControllerCode
From CSWiki
Want to plug in a generic USB controller? Use this code to see what messages it outputs.
//Basic code for game controller / joystick
//Rebecca Fiebrink, 10/9/08
Hid js;
HidMsg msg;
if(!js.openJoystick(0)) {
<<< "you are a failure" >>>;
me.exit();
}
while (true) {
js => now;
while (js.recv(msg)) {
<<< "*******NEW EVENT*********" >>>;
<<< "Which: ", msg.which>>>;
if (msg.isAxisMotion()) {
<<< "Axis motion" >>>;
}
if (msg.isButtonDown()) {
<<< "Button down" >>>;
}
if (msg.isButtonUp()) {
<<< "Button up" >>>;
}
if (msg.isMouseMotion()) {
<<< "mouse motion" >>>;
}
if (msg.isHatMotion()) {
<<< "hat motion" >>>;
}
<<< "axis position motion", msg.axisPosition >>>;
<<< "deltaX", msg.deltaX >>>;
<<< "deltaY", msg.deltaY >>>;
<<< "device num", msg.deviceNum >>>;
<<< "device type", msg.deviceType >>>;
<<< "type", msg.type >>>;
<<< "idata", msg.idata>>>;
<<< "fdata", msg.fdata >>>;
}
}