hobbyelektro

Arduino Macro Keyboard

Feb 17th, 2021
71
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "Keyboard.h"
  2.  
  3. const int buttonPin1 = 3;
  4. const int buttonPin2 = 2;
  5. const int buttonPin3 = 5;
  6. const int buttonPin4 = 4;
  7. const int buttonPin5 = 7;
  8. const int buttonPin6 = 6;
  9. const int buttonPin7 = 9;
  10. const int buttonPin8 = 8;
  11. int previousButtonState1 = LOW;
  12. int previousButtonState2 = LOW;
  13. int previousButtonState3 = LOW;
  14. int previousButtonState4 = LOW;
  15. int previousButtonState5 = LOW;
  16. int previousButtonState6 = LOW;
  17. int previousButtonState7 = LOW;
  18. int previousButtonState8 = LOW;
  19.  
  20. void setup() {
  21.   pinMode(buttonPin1, INPUT_PULLUP);
  22.   pinMode(buttonPin2, INPUT_PULLUP);
  23.   pinMode(buttonPin3, INPUT_PULLUP);
  24.   pinMode(buttonPin4, INPUT_PULLUP);
  25.   pinMode(buttonPin5, INPUT_PULLUP);
  26.   pinMode(buttonPin6, INPUT_PULLUP);
  27.   pinMode(buttonPin7, INPUT_PULLUP);
  28.   pinMode(buttonPin8, INPUT_PULLUP);
  29.   Keyboard.begin();
  30. }
  31.  
  32. void loop() {
  33.   int buttonState1 = digitalRead(buttonPin1);
  34.   int buttonState2 = digitalRead(buttonPin2);
  35.   int buttonState3 = digitalRead(buttonPin3);
  36.   int buttonState4 = digitalRead(buttonPin4);
  37.   int buttonState5 = digitalRead(buttonPin5);
  38.   int buttonState6 = digitalRead(buttonPin6);
  39.   int buttonState7 = digitalRead(buttonPin7);
  40.   int buttonState8 = digitalRead(buttonPin8);
  41.  
  42.   if ((buttonState1 != previousButtonState1)
  43.       && (buttonState1 == LOW)) {
  44.     Keyboard.write(KEY_LEFT_GUI);
  45.     delay(100);
  46.     Keyboard.println("word");
  47.     delay(100);
  48.     Keyboard.write(KEY_RETURN);  //ENTER
  49.     delay(200);
  50.   }
  51.   previousButtonState1 = buttonState1;
  52.  
  53.   if ((buttonState2 != previousButtonState2)
  54.       && (buttonState2 == LOW)) {
  55.     Keyboard.write(KEY_LEFT_GUI);
  56.     delay(100);
  57.     Keyboard.println("excel");
  58.     delay(100);
  59.     Keyboard.write(KEY_RETURN);  //ENTER
  60.     delay(200);
  61.   }
  62.   previousButtonState2 = buttonState2;
  63.  
  64.   if ((buttonState3 != previousButtonState3)
  65.       && (buttonState3 == LOW)) {
  66.     Keyboard.write(KEY_LEFT_GUI);
  67.     delay(100);
  68.     Keyboard.println("opera");
  69.     delay(100);
  70.     Keyboard.write(KEY_RETURN);  //ENTER
  71.     delay(200);
  72.   }
  73.   previousButtonState3 = buttonState3;
  74.  
  75.   if ((buttonState4 != previousButtonState4)
  76.       && (buttonState4 == LOW)) {
  77.     Keyboard.write(KEY_LEFT_GUI);
  78.     delay(100);
  79.     Keyboard.println("photoshop");
  80.     delay(100);
  81.     Keyboard.write(KEY_RETURN);  //ENTER
  82.     delay(200);
  83.   }
  84.   previousButtonState4 = buttonState4;
  85.  
  86.   if ((buttonState5 != previousButtonState5)
  87.       && (buttonState5 == LOW)) {
  88.     Keyboard.write(KEY_LEFT_GUI);
  89.     delay(100);
  90.     Keyboard.println("cura");
  91.     delay(100);
  92.     Keyboard.write(KEY_RETURN);  //ENTER
  93.     delay(200);
  94.   }
  95.   previousButtonState5 = buttonState5;
  96.  
  97.   if ((buttonState6 != previousButtonState6)
  98.       && (buttonState6 == LOW)) {
  99.     Keyboard.write(KEY_LEFT_GUI);
  100.     delay(100);
  101.     Keyboard.println("solid");
  102.     delay(100);
  103.     Keyboard.write(KEY_RETURN);  //ENTER
  104.     delay(200);
  105.   }
  106.   previousButtonState6 = buttonState6;
  107.  
  108.   if ((buttonState7 != previousButtonState7)
  109.       && (buttonState7 == LOW)) {
  110.     Keyboard.write(KEY_LEFT_GUI);
  111.     delay(100);
  112.     Keyboard.println("eagle");
  113.     delay(100);
  114.     Keyboard.write(KEY_RETURN);  //ENTER
  115.     delay(200);
  116.   }
  117.   previousButtonState7 = buttonState7;
  118.  
  119.   if ((buttonState8 != previousButtonState8)
  120.       && (buttonState8 == LOW)) {
  121.     Keyboard.write(KEY_LEFT_GUI);
  122.     delay(100);
  123.     Keyboard.println("cut");
  124.     delay(100);
  125.     Keyboard.write(KEY_RETURN);  //ENTER
  126.     delay(200);
  127.   }
  128.   previousButtonState8 = buttonState8;
  129. }
RAW Paste Data