SendMultipleKeys.ino 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /**************************************************************************
  2. *
  3. * File: SendMultipleKeys.ino
  4. * Author: Julian Schuler (https://github.com/julianschuler)
  5. * License: GNU GPLv3, see LICENSE.txt
  6. * Description: This file is an example from the USBKeyboard library.
  7. * It sends "Win+D" and "Win+E" (for Windows: show Desktop
  8. * and open Explorer) after hitting Caps Lock three times.
  9. *
  10. *************************************************************************/
  11. #include <USBKeyboard.h>
  12. /* currently available layouts: LAYOUT_US, LAYOUT_DE */
  13. #define LAYOUT LAYOUT_US
  14. /* initialize class by creating object mKeyboard */
  15. USBKeyboard mKeyboard = USBKeyboard();
  16. void setup() {
  17. /* USB timing has to be exact, therefore deactivate Timer0 interrupt */
  18. TIMSK0 = 0;
  19. }
  20. void loop() {
  21. /* call this function at least every 20ms, otherwise an USB timeout will occur */
  22. mKeyboard.update();
  23. /* check if Caps Lock was toggled at least three times */
  24. if (mKeyboard.getCapsLockToggleCount() >= 3) {
  25. /* reset Caps Lock toggle counter */
  26. mKeyboard.resetCapsLockToggleCount();
  27. /* send the E and D keys together with the GUI key (for Windows: Win key)
  28. * available modifiers: CONTROL, SHIFT, ALT, GUI */
  29. mKeyboard.sendKeys(mKeyboard.asciiToKeycode('D'), mKeyboard.asciiToKeycode('E'), 0, 0, 0, 0, MODIFIER_GUI);
  30. }
  31. /* due to the deactivation of the Timer0 interrupt, delay()
  32. * and millis() won't work, call delayMicroseconds() instead */
  33. delayMicroseconds(20000);
  34. }