| 1 |
//----------------------------------------------------------------------------- |
| 2 |
// name: mouse-abs.ck |
| 3 |
// desc: basic mouse input (absolute normalized screen X Y coordinates) |
| 4 |
// ALSO SEE mouse.ck for relative X Y deltas |
| 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 |
// get the normalized X-Y screen cursor pofaition |
| 45 |
<<< "mouse normalized position --", |
| 46 |
"x:", msg.scaledCursorX, "y:", msg.scaledCursorY >>>; |
| 47 |
} |
| 48 |
|
| 49 |
// mouse button down |
| 50 |
else if( msg.isButtonDown() ) |
| 51 |
{ |
| 52 |
<<< "mouse button", msg.which, "down" >>>; |
| 53 |
} |
| 54 |
|
| 55 |
// mouse button up |
| 56 |
else if( msg.isButtonUp() ) |
| 57 |
{ |
| 58 |
<<< "mouse button", msg.which, "up" >>>; |
| 59 |
} |
| 60 |
|
| 61 |
// mouse wheel motion |
| 62 |
else if( msg.isWheelMotion() ) |
| 63 |
{ |
| 64 |
if( msg.deltaX ) |
| 65 |
{ |
| 66 |
<<< "mouse wheel:", msg.deltaX, "on x-axis" >>>; |
| 67 |
} |
| 68 |
|
| 69 |
if( msg.deltaY ) |
| 70 |
{ |
| 71 |
<<< "mouse wheel:", msg.deltaY, "on y-axis" >>>; |
| 72 |
} |
| 73 |
} |
| 74 |
} |
| 75 |
} |