source: rtos_arduino/trunk/arduino_lib/libraries/USBHost/examples/KeyboardController/KeyboardController.ino@ 136

Last change on this file since 136 was 136, checked in by ertl-honda, 8 years ago

ライブラリとOS及びベーシックなサンプルの追加.

File size: 1.6 KB
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
20USBHost usb;
21
22// Attach keyboard controller to USB
23KeyboardController keyboard(usb);
24
25// This function intercepts key press
26void keyPressed() {
27 Serial.print("Pressed: ");
28 printKey();
29}
30
31// This function intercepts key release
32void keyReleased() {
33 Serial.print("Released: ");
34 printKey();
35}
36
37void 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
72void setup()
73{
74 Serial.begin(9600);
75 Serial.println("Program started");
76 delay(200);
77}
78
79void loop()
80{
81 // Process USB tasks
82 usb.Task();
83}
Note: See TracBrowser for help on using the repository browser.