// // Hotkey Generator // // crustytech.com // #include "HID-Project.h" // Define Arduino pin numbers for buttons #define BTN1 8 #define BTN2 9 #define BTN3 10 #define BTN4 A0 #define NUMBUTTONS 4 int buttons[NUMBUTTONS] = {BTN1, BTN2, BTN3, BTN4}; unsigned long btntime[NUMBUTTONS]; boolean btnpress[NUMBUTTONS]; char line[80]; unsigned long t; int n; void setup() { for (int i = 0; i < NUMBUTTONS; i++) { pinMode(buttons[i], INPUT_PULLUP); btntime[i] = 0; btnpress[i] = false; } BootKeyboard.begin(); } void loop() { int leds; for (int i = 0; i < NUMBUTTONS; i++) { if (!digitalRead(buttons[i])) { // Button pressed (negative logic) if (btntime[i] == 0) { // Button has just been pressed btntime[i] = millis(); } else { // Button is still pressed if (millis() - btntime[i] > 20 && !btnpress[i]) { // This is not just a glitch btnpress[i] = true; // Now do your stuff! switch (i) { #if 1 //// LOCK SCREEN // Mac case 0: // CMD+CTRL+Q BootKeyboard.press(KEY_LEFT_GUI); BootKeyboard.press(KEY_LEFT_CTRL); BootKeyboard.write(KEY_Q); BootKeyboard.release(KEY_LEFT_CTRL); BootKeyboard.release(KEY_LEFT_GUI); break; // Windows case 1: // WIN+L BootKeyboard.press(KEY_LEFT_GUI); BootKeyboard.write(KEY_L); BootKeyboard.release(KEY_LEFT_GUI); break; //// TOGGLE AUDIO // Mac case 2: // CMD+SHFT+A (Zoom) BootKeyboard.press(KEY_LEFT_GUI); BootKeyboard.press(KEY_LEFT_SHIFT); BootKeyboard.write(KEY_A); BootKeyboard.release(KEY_LEFT_SHIFT); BootKeyboard.release(KEY_LEFT_GUI); break; // Windows case 3: // Alt-A: Toggle Audio (Zoom) BootKeyboard.press(KEY_LEFT_ALT); BootKeyboard.write(KEY_A); BootKeyboard.release(KEY_LEFT_ALT); break; #else case 0: BootKeyboard.write(KEY_0); break; case 1: BootKeyboard.write(KEY_1); break; case 2: BootKeyboard.write(KEY_2); break; case 3: BootKeyboard.write(KEY_3); break; #endif } } } } else { // Button not pressed if (btntime[i] != 0) { // Looks like it's just been released btntime[i] = 0; btnpress[i] = false; } } } }