skizziks_53

Pro Micro Zoom Controller v1.0

Sep 8th, 2020 (edited)
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.20 KB | None | 0 0
  1. /*
  2.   Reddit - 8 September 2020
  3.   Zoom app single-button controller, v1.0
  4.  
  5.   This sketch is written for a Pro Micro/Leonardo board, although the original (elliotmade) example used a Digispark.
  6.  
  7.   In the Arduino IDE, you need to set the Arduino IDE board type to "Leonardo".
  8.   There is no Pro Micro board type, as it's functionally the same thing as a Leonardo board.
  9.  
  10.   This is one link that details using a Pro Micro/Leonardo as a keyboard-
  11.   https://www.arduino.cc/reference/en/language/functions/usb/keyboard/
  12. */
  13.  
  14. //Elliotmade 4/22/2020<br>//https://elliotmade.com/2020/04/23/physical-mute-button-for-zoom-meetings/
  15. //https://www.youtube.com/watch?v=apGbelheIzg
  16. //Used a digispark clone
  17.  
  18. /*
  19.   The Zoom key presses it emulates are as follows:
  20.  
  21.   CTRL+ALT+SHIFT brings focus to the Zoom window
  22.  
  23.   ALT+A toggles the state of mute, if you mute is on it turns it off, and if it's off it turns it on
  24.  
  25.   ALT+Q leaves a meeting or ends it if you are the host
  26.  
  27.   (~~~~~~note that this example sketch only had two of the functions defined~~~~~~~~~)
  28. */
  29.  
  30. //this will switch to the zoom application and mute it or exit on long press
  31. //momentary button on pin 0 with pullup resistor
  32.  
  33. #include "Keyboard.h" // <-------------------> standard Arduino atmega32u4 keyboard library. You need to include this to use a Leonardo board as a keyboard.
  34.  
  35. //https://github.com/mathertel/OneButton
  36. //button library
  37. #include "OneButton.h"
  38.  
  39. //int button1pin = 0; --------------> This won't work here.
  40. // On the ATMega32U4 boards, pins zero and 1 are the signal pins for the USB interface.
  41. // What that means is if you are going to use the USB connection when the sketch is running, you cannot use pins zero and 1 at all for your own purposes.
  42. // So you need to change your button pin to another pin, as below.
  43. int button1pin = 2;
  44. // This button apparently needs to be active==HIGH, so you need a pull-down resistor on it.
  45.  
  46.  
  47. /*
  48.   //https://github.com/digistump/DigisparkArduinoIntegration/blob/master/libraries/DigisparkKeyboard/DigiKeyboard.h
  49.   //#include "DigiKeyboard.h" ------------------> You don't need this at all because you aren't using a DigiSpark board here.
  50. */
  51.  
  52. /*
  53.   The Arduino keyboard.h library already defines all the normal modifier keys, so you don't need to do that.
  54.   (from https://www.sparkfun.com/tutorials/337 )
  55.  
  56.   #define KEY_LEFT_CTRL  0x80
  57.   #define KEY_LEFT_SHIFT 0x81
  58.   #define KEY_LEFT_ALT   0x82
  59.   #define KEY_LEFT_GUI   0x83
  60.   #define KEY_RIGHT_CTRL 0x84
  61.   #define KEY_RIGHT_SHIFT    0x85
  62.   #define KEY_RIGHT_ALT  0x86
  63.   #define KEY_RIGHT_GUI  0x87
  64.  
  65.   #define KEY_UP_ARROW   0xDA
  66.   #define KEY_DOWN_ARROW 0xD9
  67.   #define KEY_LEFT_ARROW 0xD8
  68.   #define KEY_RIGHT_ARROW    0xD7
  69.   #define KEY_BACKSPACE  0xB2
  70.   #define KEY_TAB        0xB3
  71.   #define KEY_RETURN 0xB0
  72.   #define KEY_ESC        0xB1
  73.   #define KEY_INSERT 0xD1
  74.   #define KEY_DELETE 0xD4
  75.   #define KEY_PAGE_UP    0xD3
  76.   #define KEY_PAGE_DOWN  0xD6
  77.   #define KEY_HOME   0xD2
  78.   #define KEY_END        0xD5
  79.   #define KEY_CAPS_LOCK  0xC1
  80.   #define KEY_F1     0xC2
  81.   #define KEY_F2     0xC3
  82.   #define KEY_F3     0xC4
  83.   #define KEY_F4     0xC5
  84.   #define KEY_F5     0xC6
  85.   #define KEY_F6     0xC7
  86.   #define KEY_F7     0xC8
  87.   #define KEY_F8     0xC9
  88.   #define KEY_F9     0xCA
  89.   #define KEY_F10        0xCB
  90.   #define KEY_F11        0xCC
  91.   #define KEY_F12        0xCD
  92. */
  93.  
  94. //set up buttons
  95. OneButton button1(button1pin, true);
  96.  
  97.  
  98.  
  99. void setup() {
  100.   // put your setup code here, to run once:
  101.  
  102.   /*
  103.     It looks like the button pin should be active == LOW, since the OneButton.tick(void) function checks for a value above zero?
  104.     I dunno how Digisparks are set up normally.
  105.   */
  106.   //pinMode(button1pin, INPUT_PULLUP); // This line is setting the pullup resistor on the button pin here. This might be wrong though?
  107.  
  108.   //set up button functions
  109.   button1.attachClick(click1); // ------- (click1 is a function name to attach)
  110.   button1.attachLongPressStart(longPressStart1); // ------- (longPressStart1 is a function name to attach)
  111.  
  112.   // DigiKeyboard.sendKeyStroke(0);
  113.   // DigiKeyboard.delay(500);
  114.   Keyboard.begin(); // --------------- https://www.arduino.cc/reference/en/language/functions/usb/keyboard/keyboardbegin/
  115. }
  116. void loop() {
  117.   // put your main code here, to run repeatedly:
  118.   //monitor buttons
  119.   button1.tick();
  120. }
  121.  
  122. // This function will be called when the button1 was pressed 1 time (and no 2. button press followed).
  123. void click1() {
  124.  
  125.   Keyboard.press(KEY_LEFT_CTRL);
  126.   Keyboard.press(KEY_LEFT_ALT);
  127.   Keyboard.press(KEY_LEFT_SHIFT);
  128.  
  129.   Keyboard.release(KEY_LEFT_CTRL);
  130.   Keyboard.release(KEY_LEFT_ALT);
  131.   Keyboard.release(KEY_LEFT_SHIFT);
  132.  
  133.   delay(100);
  134.  
  135.   Keyboard.press(KEY_LEFT_ALT);
  136.   Keyboard.press('A');
  137.   Keyboard.release(KEY_LEFT_ALT);
  138.  
  139.   /*
  140.     // this is generally not necessary but with some older systems it seems to
  141.     // prevent missing the first character after a delay:
  142.     DigiKeyboard.sendKeyStroke(0);
  143.  
  144.     // Type out this string letter by letter on the computer (assumes US-style
  145.     // keyboard)
  146.     //DigiKeyboard.sendKeyStroke(0, MOD_SHIFT_LEFT | MOD_CONTROL_LEFT | MOD_ALT_LEFT);
  147.     DigiKeyboard.delay(100);
  148.     DigiKeyboard.sendKeyStroke(KEY_A, MOD_ALT_LEFT);
  149.   */
  150.  
  151. } // click1
  152.  
  153. // This function will be called once, when the button1 is pressed for a long time.
  154. void longPressStart1() {
  155.  
  156.   Keyboard.press(KEY_LEFT_CTRL);
  157.   Keyboard.press(KEY_LEFT_ALT);
  158.   Keyboard.press(KEY_LEFT_SHIFT);
  159.  
  160.   Keyboard.release(KEY_LEFT_CTRL);
  161.   Keyboard.release(KEY_LEFT_ALT);
  162.   Keyboard.release(KEY_LEFT_SHIFT);
  163.  
  164.   delay(50);
  165.  
  166.   Keyboard.press(KEY_LEFT_ALT);
  167.   Keyboard.write('Q');
  168.   Keyboard.release(KEY_LEFT_ALT);
  169.  
  170.   delay(50);
  171.  
  172.   Keyboard.write(KEY_RETURN);
  173.  
  174.   /*
  175.     // this is generally not necessary but with some older systems it seems to
  176.     // prevent missing the first character after a delay:
  177.     DigiKeyboard.sendKeyStroke(0);
  178.  
  179.     // Type out this string letter by letter on the computer (assumes US-style
  180.     // keyboard)
  181.     DigiKeyboard.sendKeyStroke(0, MOD_SHIFT_LEFT | MOD_CONTROL_LEFT | MOD_ALT_LEFT);
  182.     DigiKeyboard.delay(50);
  183.     DigiKeyboard.sendKeyStroke(KEY_Q, MOD_ALT_LEFT);
  184.     DigiKeyboard.delay(50);
  185.     DigiKeyboard.sendKeyStroke(KEY_ENTER);
  186.   */
  187. } // longPressStart1
Add Comment
Please, Sign In to add comment