TolentinoCotesta

HID Keyboard

Oct 26th, 2020 (edited)
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.02 KB | None | 0 0
  1. /*
  2.   Copyright (c) 2014-2015 NicoHood
  3.   See the readme for credit to other people.
  4.  
  5.   Improved Keyboard example
  6.  
  7.   Shows how to use the new Keyboard API.
  8.  
  9.   See HID Project documentation for more information.
  10.   https://github.com/NicoHood/HID/wiki/Keyboard-API#improved-keyboard
  11. */
  12.  
  13. #include "HID-Project.h"
  14. #include "keycode.h"
  15.  
  16. const int pinLed = LED_BUILTIN;
  17. const int pinButton = 2;
  18.  
  19. void setup() {
  20.   pinMode(pinLed, OUTPUT);
  21.   pinMode(pinButton, INPUT_PULLUP);
  22.  
  23.   // Sends a clean report to the host. This is important on any Arduino type.
  24.   Keyboard.begin();
  25.  
  26.   delay(5000);
  27.    // Use the default print functions
  28.    Keyboard.println("Arduino Leonardo will open a browser...");
  29.    delay(1000);
  30.  
  31.    // Sends a clean report to the host. This is important on any Arduino type.
  32.    Consumer.begin();
  33.    Consumer.write(CONSUMER_BROWSER_HOME);
  34. }
  35.  
  36.  
  37. void loop() {
  38.   // Trigger caps lock manually via button
  39.   if (!digitalRead(pinButton)) {
  40.     digitalWrite(pinLed, HIGH);
  41.  
  42.     // Use the default print functions
  43.     Keyboard.println("Hello World!");
  44.  
  45.     // Press a single character, special non ascii characters wont work.
  46.     //Keyboard.write('a');
  47.  
  48.     // Write single keys, do not use a number here!
  49.     //Keyboard.write(KEY_ENTER);
  50.  
  51.  
  52.     // If you really wish to press a RAW keycode without the name use this:
  53.     //Keyboard.write(KeyboardKeycode(40));
  54.  
  55.     // Use (a limited number of) consumer keys.
  56.     // Only works with the lower 255 keys and on linux only.
  57.     //Keyboard.write(MEDIA_PLAY_PAUSE);
  58.  
  59.     // Linux also supports several system function via consumer report.
  60.     //Keyboard.write(CONSUMER_POWER);
  61.     //Keyboard.write(CONSUMER_SLEEP);
  62.  
  63.     // You can also use some special keyboard keys on linux.
  64.     //Keyboard.write(KEY_POWER);
  65.     //Keyboard.write(KEY_F13);
  66.  
  67.     // You can wakeup you PC from sleep.
  68.     // This might be not supported on all hardware, but on all OS types.
  69.     //Keyboard.wakeupHost();
  70.  
  71.     // Simple debounce
  72.     delay(300);
  73.     digitalWrite(pinLed, LOW);
  74.   }
  75. }
Add Comment
Please, Sign In to add comment