From e8ca301007d26914cf04afe47f2e73c4d6324b42 Mon Sep 17 00:00:00 2001 From: Nico Date: Sat, 11 Apr 2015 09:31:32 +0200 Subject: [PATCH] Added Keycode example --- .../HID/Keyboard_Keycode/Keyboard_Keycode.ino | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 examples/HID/Keyboard_Keycode/Keyboard_Keycode.ino diff --git a/examples/HID/Keyboard_Keycode/Keyboard_Keycode.ino b/examples/HID/Keyboard_Keycode/Keyboard_Keycode.ino new file mode 100644 index 0000000..d195dcd --- /dev/null +++ b/examples/HID/Keyboard_Keycode/Keyboard_Keycode.ino @@ -0,0 +1,56 @@ +/* + Copyright (c) 2014 NicoHood + See the readme for credit to other people. + + Keyboard Keycode example + + Press a button to write some text to your pc. + This example is made for advanced users, to add specific keys to the HID report. + See official and HID Project and USB docs documentation for more infos + https://github.com/NicoHood/HID/wiki/Keyboard-API + http://www.usb.org/developers/hidpage/Hut1_12v2.pdf +*/ + +const int pinLed = LED_BUILTIN; +const int pinButton = 2; + +void setup() { + pinMode(pinLed, OUTPUT); + pinMode(pinButton, INPUT_PULLUP); + + // Sends a clean report to the host. This is important on any Arduino type. + Keyboard.begin(); +} + +void loop() { + if (!digitalRead(pinButton)) { + digitalWrite(pinLed, HIGH); + + // the "normal" way + //Keyboard.println("Test"); + + // press 'a' via normal API + //Keyboard.write('a'); + + // press 'a' via keycodes + Keyboard.writeKeycode(0x04); + + // press the contect menu button via normal API + //Keyboard.write(KEY_MENU); + + // press the context menu button via keycodes (right mouse click) + //Keyboard.writeKeycode(0x65); + + // You can also try some specific keys that do not work on every OS + /* + #define HID_KEYBOARD_MUTE 0x7F + #define HID_KEYBOARD_VOLUME_UP 0x80 + #define HID_KEYBOARD_VOLUME_DOWN 0x81 + */ + //Keyboard.writeKeycode(0x7F); + + // simple debounce + delay(300); + digitalWrite(pinLed, LOW); + } +}