2012-10-08 19:38:01 +02:00
|
|
|
/*
|
2012-10-21 18:36:54 +02:00
|
|
|
Keyboard Controller Example
|
2012-10-08 19:38:01 +02:00
|
|
|
|
2012-10-21 18:36:54 +02:00
|
|
|
Shows the output of a USB Keyboard connected to
|
|
|
|
the Native USB port on an Arduino Due Board.
|
2012-10-08 19:38:01 +02:00
|
|
|
|
|
|
|
created 8 Oct 2012
|
|
|
|
by Cristian Maglie
|
2012-10-21 18:36:54 +02:00
|
|
|
|
|
|
|
http://arduino.cc/en/Tutorial/KeyboardController
|
|
|
|
|
|
|
|
This samlple code is part of the public domain.
|
2012-10-08 19:38:01 +02:00
|
|
|
*/
|
|
|
|
|
2012-10-21 18:36:54 +02:00
|
|
|
|
2012-10-08 19:38:01 +02:00
|
|
|
// Require keyboard control library
|
|
|
|
#include <KeyboardController.h>
|
|
|
|
|
|
|
|
// Initialize USB Controller
|
|
|
|
USBHost usb;
|
|
|
|
|
|
|
|
// Attach keyboard controller to USB
|
|
|
|
KeyboardController keyboard(usb);
|
|
|
|
|
|
|
|
// This function intercepts key press
|
|
|
|
void keyPressed() {
|
|
|
|
Serial.print("Pressed: ");
|
|
|
|
printKey();
|
|
|
|
}
|
|
|
|
|
|
|
|
// This function intercepts key release
|
|
|
|
void keyReleased() {
|
|
|
|
Serial.print("Released: ");
|
|
|
|
printKey();
|
|
|
|
}
|
|
|
|
|
|
|
|
void printKey() {
|
|
|
|
// getOemKey() returns the OEM-code associated with the key
|
|
|
|
Serial.print(" key:");
|
|
|
|
Serial.print(keyboard.getOemKey());
|
|
|
|
|
|
|
|
// getModifiers() returns a bits field with the modifiers-keys
|
|
|
|
int mod = keyboard.getModifiers();
|
|
|
|
Serial.print(" mod:");
|
|
|
|
Serial.print(mod);
|
|
|
|
|
|
|
|
Serial.print(" => ");
|
|
|
|
|
|
|
|
if (mod & LeftCtrl)
|
|
|
|
Serial.print("L-Ctrl ");
|
|
|
|
if (mod & LeftShift)
|
|
|
|
Serial.print("L-Shift ");
|
|
|
|
if (mod & Alt)
|
|
|
|
Serial.print("Alt ");
|
|
|
|
if (mod & LeftCmd)
|
|
|
|
Serial.print("L-Cmd ");
|
|
|
|
if (mod & RightCtrl)
|
|
|
|
Serial.print("R-Ctrl ");
|
|
|
|
if (mod & RightShift)
|
|
|
|
Serial.print("R-Shift ");
|
|
|
|
if (mod & AltGr)
|
|
|
|
Serial.print("AltGr ");
|
|
|
|
if (mod & RightCmd)
|
|
|
|
Serial.print("R-Cmd ");
|
|
|
|
|
|
|
|
// getKey() returns the ASCII translation of OEM key
|
|
|
|
// combined with modifiers.
|
|
|
|
Serial.write(keyboard.getKey());
|
|
|
|
Serial.println();
|
|
|
|
}
|
|
|
|
|
|
|
|
void setup()
|
|
|
|
{
|
2012-10-21 18:36:54 +02:00
|
|
|
Serial.begin(9600);
|
2012-10-08 19:38:01 +02:00
|
|
|
Serial.println("Program started");
|
|
|
|
delay(200);
|
|
|
|
}
|
|
|
|
|
|
|
|
void loop()
|
|
|
|
{
|
|
|
|
// Process USB tasks
|
|
|
|
usb.Task();
|
|
|
|
}
|