| 1 |
//----------------------------------------------------------------------------- |
| 2 |
// name: joy.ck |
| 3 |
// desc: basic joystick/gamepad input |
| 4 |
// |
| 5 |
// note: select between joysticks by specifying device number; |
| 6 |
// to see a list of devices and their numbers, either... |
| 7 |
// 1) view the Device Browser window in miniAudicle (select |
| 8 |
// "Human Interface Devices" in the drop-down menu) |
| 9 |
// OR 2) from the command line: |
| 10 |
// > chuck --probe |
| 11 |
// |
| 12 |
// note (Windows only): XBox One controllers may not generate input |
| 13 |
// for HID without the following workaround: |
| 14 |
// |
| 15 |
// from otherTom#4512 on snes9x.com forum |
| 16 |
// *** open up Device Manager, expand "Human Interface Devices", |
| 17 |
// right click "XINPUT compatible HID device", "Update driver", |
| 18 |
// "Browse my computer", "Let me pick". should be three options. |
| 19 |
// Try "HID-compliant game controller". If you want to undo the |
| 20 |
// change, same thing but update "HID-compliant game controller" |
| 21 |
// and pick the XINPUT *** |
| 22 |
// https://www.snes9x.com/phpbb3/viewtopic.php?t=27510&sid=661fbbc1609037a8ec2e5f10e003f5a0 |
| 23 |
//----------------------------------------------------------------------------- |
| 24 |
|
| 25 |
// HID input and HID message |
| 26 |
Hid hi; |
| 27 |
HidMsg msg; |
| 28 |
|
| 29 |
// which joystick |
| 30 |
0 => int device; |
| 31 |
// get from command line |
| 32 |
if( me.args() ) me.arg(0) => Std.atoi => device; |
| 33 |
|
| 34 |
// open joystick 0, exit on fail |
| 35 |
if( !hi.openJoystick( device ) ) me.exit(); |
| 36 |
|
| 37 |
<<< "joystick '" + hi.name() + "' ready", "" >>>; |
| 38 |
|
| 39 |
// infinite event loop |
| 40 |
while( true ) |
| 41 |
{ |
| 42 |
// wait on HidIn as event |
| 43 |
hi => now; |
| 44 |
|
| 45 |
// messages received |
| 46 |
while( hi.recv( msg ) ) |
| 47 |
{ |
| 48 |
// joystick axis motion |
| 49 |
if( msg.isAxisMotion() ) |
| 50 |
{ |
| 51 |
<<< "joystick axis", msg.which, ":", msg.axisPosition >>>; |
| 52 |
} |
| 53 |
|
| 54 |
// joystick button down |
| 55 |
else if( msg.isButtonDown() ) |
| 56 |
{ |
| 57 |
<<< "joystick button", msg.which, "down" >>>; |
| 58 |
} |
| 59 |
|
| 60 |
// joystick button up |
| 61 |
else if( msg.isButtonUp() ) |
| 62 |
{ |
| 63 |
<<< "joystick button", msg.which, "up" >>>; |
| 64 |
} |
| 65 |
|
| 66 |
// joystick hat/POV switch/d-pad motion |
| 67 |
else if( msg.isHatMotion() ) |
| 68 |
{ |
| 69 |
<<< "joystick hat", msg.which, ":", msg.idata >>>; |
| 70 |
} |
| 71 |
} |
| 72 |
} |