Debian Codegraph @

examples/hid/kb.ck

raw
1 //-----------------------------------------------------------------------------
2 // name: kb.ck
3 // desc: open a keyboard and listen for key-down and key-up events
4 //
5 // note: select between keyboards by specifying the 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 // author: Ge Wang (https://ccrma.stanford.edu/~ge/)
13 //-----------------------------------------------------------------------------
14 Hid hi;
15 HidMsg msg;
16
17 // which keyboard
18 0 => int device;
19 // get from command line
20 if( me.args() ) me.arg(0) => Std.atoi => device;
21
22 // open keyboard (get device number from command line)
23 if( !hi.openKeyboard( device ) ) me.exit();
24 <<< "keyboard '" + hi.name() + "' ready", "" >>>;
25
26 // infinite event loop
27 while( true )
28 {
29 // wait on event
30 hi => now;
31
32 // get one or more messages
33 while( hi.recv( msg ) )
34 {
35 // check for action type
36 if( msg.isButtonDown() )
37 {
38 <<< "down:", msg.which, "(code)", msg.key, "(usb key)", msg.ascii, "(ascii)" >>>;
39 }
40
41 else
42 {
43 //<<< "up:", msg.which, "(code)", msg.key, "(usb key)", msg.ascii, "(ascii)" >>>;
44 }
45 }
46 }