Line | |
---|
1 | /*
|
---|
2 | Keyboard Controller Example
|
---|
3 |
|
---|
4 | Shows the output of a USB Keyboard connected to
|
---|
5 | the Native USB port on an Arduino Due Board.
|
---|
6 |
|
---|
7 | created 8 Oct 2012
|
---|
8 | by Cristian Maglie
|
---|
9 |
|
---|
10 | http://arduino.cc/en/Tutorial/KeyboardController
|
---|
11 |
|
---|
12 | This sample code is part of the public domain.
|
---|
13 | */
|
---|
14 |
|
---|
15 |
|
---|
16 | // Require keyboard control library
|
---|
17 | #include <KeyboardController.h>
|
---|
18 |
|
---|
19 | // Initialize USB Controller
|
---|
20 | USBHost usb;
|
---|
21 |
|
---|
22 | // Attach keyboard controller to USB
|
---|
23 | KeyboardController keyboard(usb);
|
---|
24 |
|
---|
25 | // This function intercepts key press
|
---|
26 | void keyPressed() {
|
---|
27 | Serial.print("Pressed: ");
|
---|
28 | printKey();
|
---|
29 | }
|
---|
30 |
|
---|
31 | // This function intercepts key release
|
---|
32 | void keyReleased() {
|
---|
33 | Serial.print("Released: ");
|
---|
34 | printKey();
|
---|
35 | }
|
---|
36 |
|
---|
37 | void printKey() {
|
---|
38 | // getOemKey() returns the OEM-code associated with the key
|
---|
39 | Serial.print(" key:");
|
---|
40 | Serial.print(keyboard.getOemKey());
|
---|
41 |
|
---|
42 | // getModifiers() returns a bits field with the modifiers-keys
|
---|
43 | int mod = keyboard.getModifiers();
|
---|
44 | Serial.print(" mod:");
|
---|
45 | Serial.print(mod);
|
---|
46 |
|
---|
47 | Serial.print(" => ");
|
---|
48 |
|
---|
49 | if (mod & LeftCtrl)
|
---|
50 | Serial.print("L-Ctrl ");
|
---|
51 | if (mod & LeftShift)
|
---|
52 | Serial.print("L-Shift ");
|
---|
53 | if (mod & Alt)
|
---|
54 | Serial.print("Alt ");
|
---|
55 | if (mod & LeftCmd)
|
---|
56 | Serial.print("L-Cmd ");
|
---|
57 | if (mod & RightCtrl)
|
---|
58 | Serial.print("R-Ctrl ");
|
---|
59 | if (mod & RightShift)
|
---|
60 | Serial.print("R-Shift ");
|
---|
61 | if (mod & AltGr)
|
---|
62 | Serial.print("AltGr ");
|
---|
63 | if (mod & RightCmd)
|
---|
64 | Serial.print("R-Cmd ");
|
---|
65 |
|
---|
66 | // getKey() returns the ASCII translation of OEM key
|
---|
67 | // combined with modifiers.
|
---|
68 | Serial.write(keyboard.getKey());
|
---|
69 | Serial.println();
|
---|
70 | }
|
---|
71 |
|
---|
72 | void setup()
|
---|
73 | {
|
---|
74 | Serial.begin(9600);
|
---|
75 | Serial.println("Program started");
|
---|
76 | delay(200);
|
---|
77 | }
|
---|
78 |
|
---|
79 | void loop()
|
---|
80 | {
|
---|
81 | // Process USB tasks
|
---|
82 | usb.Task();
|
---|
83 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.