| 1 |
//----------------------------------------------------------------------------- |
| 2 |
// name: mouse.ck |
| 3 |
// desc: basic mouse input (relative X and Y deltas) |
| 4 |
// ALSO SEE mouse-abs.ck for absolute screen position |
| 5 |
// ALSO SEE mouse-cursor.ck for mouse cursor tracking... |
| 6 |
// (MouseCursor is both absolute and scaled and is a different |
| 7 |
// and simpler mechanism for mouse position input) |
| 8 |
// |
| 9 |
// note: select between mice/trackpads by specifying device number; |
| 10 |
// to see a list of devices and their numbers, either... |
| 11 |
// 1) view the Device Browser window in miniAudicle (select |
| 12 |
// "Human Interface Devices" in the drop-down menu) |
| 13 |
// OR 2) from the command line: |
| 14 |
// > chuck --probe |
| 15 |
// |
| 16 |
// author: Ge Wang (https://ccrma.stanford.edu/~ge/) |
| 17 |
//----------------------------------------------------------------------------- |
| 18 |
|
| 19 |
// HID input and a HID message |
| 20 |
Hid hi; |
| 21 |
HidMsg msg; |
| 22 |
|
| 23 |
// which mouse |
| 24 |
0 => int device; |
| 25 |
// get from command line |
| 26 |
if( me.args() ) me.arg(0) => Std.atoi => device; |
| 27 |
|
| 28 |
// open mouse 0, exit on fail |
| 29 |
if( !hi.openMouse( device ) ) me.exit(); |
| 30 |
<<< "mouse '" + hi.name() + "' ready", "" >>>; |
| 31 |
|
| 32 |
// infinite event loop |
| 33 |
while( true ) |
| 34 |
{ |
| 35 |
// wait on HidIn as event |
| 36 |
hi => now; |
| 37 |
|
| 38 |
// messages received |
| 39 |
while( hi.recv( msg ) ) |
| 40 |
{ |
| 41 |
// mouse motion |
| 42 |
if( msg.isMouseMotion() ) |
| 43 |
{ |
| 44 |
if( msg.deltaX ) |
| 45 |
{ |
| 46 |
<<< "mouse motion:", msg.deltaX, "on x-axis" >>>; |
| 47 |
} |
| 48 |
if( msg.deltaY ) |
| 49 |
{ |
| 50 |
<<< "mouse motion:", msg.deltaY, "on y-axis" >>>; |
| 51 |
} |
| 52 |
} |
| 53 |
|
| 54 |
// mouse button down |
| 55 |
else if( msg.isButtonDown() ) |
| 56 |
{ |
| 57 |
<<< "mouse button", msg.which, "down" >>>; |
| 58 |
} |
| 59 |
|
| 60 |
// mouse button up |
| 61 |
else if( msg.isButtonUp() ) |
| 62 |
{ |
| 63 |
<<< "mouse button", msg.which, "up" >>>; |
| 64 |
} |
| 65 |
|
| 66 |
// mouse wheel motion |
| 67 |
else if( msg.isWheelMotion() ) |
| 68 |
{ |
| 69 |
if( msg.deltaX ) |
| 70 |
{ |
| 71 |
<<< "mouse wheel:", msg.deltaX, "on x-axis" >>>; |
| 72 |
} |
| 73 |
|
| 74 |
if( msg.deltaY ) |
| 75 |
{ |
| 76 |
<<< "mouse wheel:", msg.deltaY, "on y-axis" >>>; |
| 77 |
} |
| 78 |
} |
| 79 |
} |
| 80 |
} |