Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Reddit - 8 September 2020
- Zoom app single-button controller, v1.0
- This sketch is written for a Pro Micro/Leonardo board, although the original (elliotmade) example used a Digispark.
- In the Arduino IDE, you need to set the Arduino IDE board type to "Leonardo".
- There is no Pro Micro board type, as it's functionally the same thing as a Leonardo board.
- This is one link that details using a Pro Micro/Leonardo as a keyboard-
- https://www.arduino.cc/reference/en/language/functions/usb/keyboard/
- */
- //Elliotmade 4/22/2020<br>//https://elliotmade.com/2020/04/23/physical-mute-button-for-zoom-meetings/
- //https://www.youtube.com/watch?v=apGbelheIzg
- //Used a digispark clone
- /*
- The Zoom key presses it emulates are as follows:
- CTRL+ALT+SHIFT brings focus to the Zoom window
- 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
- ALT+Q leaves a meeting or ends it if you are the host
- (~~~~~~note that this example sketch only had two of the functions defined~~~~~~~~~)
- */
- //this will switch to the zoom application and mute it or exit on long press
- //momentary button on pin 0 with pullup resistor
- #include "Keyboard.h" // <-------------------> standard Arduino atmega32u4 keyboard library. You need to include this to use a Leonardo board as a keyboard.
- //https://github.com/mathertel/OneButton
- //button library
- #include "OneButton.h"
- //int button1pin = 0; --------------> This won't work here.
- // On the ATMega32U4 boards, pins zero and 1 are the signal pins for the USB interface.
- // 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.
- // So you need to change your button pin to another pin, as below.
- int button1pin = 2;
- // This button apparently needs to be active==HIGH, so you need a pull-down resistor on it.
- /*
- //https://github.com/digistump/DigisparkArduinoIntegration/blob/master/libraries/DigisparkKeyboard/DigiKeyboard.h
- //#include "DigiKeyboard.h" ------------------> You don't need this at all because you aren't using a DigiSpark board here.
- */
- /*
- The Arduino keyboard.h library already defines all the normal modifier keys, so you don't need to do that.
- (from https://www.sparkfun.com/tutorials/337 )
- #define KEY_LEFT_CTRL 0x80
- #define KEY_LEFT_SHIFT 0x81
- #define KEY_LEFT_ALT 0x82
- #define KEY_LEFT_GUI 0x83
- #define KEY_RIGHT_CTRL 0x84
- #define KEY_RIGHT_SHIFT 0x85
- #define KEY_RIGHT_ALT 0x86
- #define KEY_RIGHT_GUI 0x87
- #define KEY_UP_ARROW 0xDA
- #define KEY_DOWN_ARROW 0xD9
- #define KEY_LEFT_ARROW 0xD8
- #define KEY_RIGHT_ARROW 0xD7
- #define KEY_BACKSPACE 0xB2
- #define KEY_TAB 0xB3
- #define KEY_RETURN 0xB0
- #define KEY_ESC 0xB1
- #define KEY_INSERT 0xD1
- #define KEY_DELETE 0xD4
- #define KEY_PAGE_UP 0xD3
- #define KEY_PAGE_DOWN 0xD6
- #define KEY_HOME 0xD2
- #define KEY_END 0xD5
- #define KEY_CAPS_LOCK 0xC1
- #define KEY_F1 0xC2
- #define KEY_F2 0xC3
- #define KEY_F3 0xC4
- #define KEY_F4 0xC5
- #define KEY_F5 0xC6
- #define KEY_F6 0xC7
- #define KEY_F7 0xC8
- #define KEY_F8 0xC9
- #define KEY_F9 0xCA
- #define KEY_F10 0xCB
- #define KEY_F11 0xCC
- #define KEY_F12 0xCD
- */
- //set up buttons
- OneButton button1(button1pin, true);
- void setup() {
- // put your setup code here, to run once:
- /*
- It looks like the button pin should be active == LOW, since the OneButton.tick(void) function checks for a value above zero?
- I dunno how Digisparks are set up normally.
- */
- //pinMode(button1pin, INPUT_PULLUP); // This line is setting the pullup resistor on the button pin here. This might be wrong though?
- //set up button functions
- button1.attachClick(click1); // ------- (click1 is a function name to attach)
- button1.attachLongPressStart(longPressStart1); // ------- (longPressStart1 is a function name to attach)
- // DigiKeyboard.sendKeyStroke(0);
- // DigiKeyboard.delay(500);
- Keyboard.begin(); // --------------- https://www.arduino.cc/reference/en/language/functions/usb/keyboard/keyboardbegin/
- }
- void loop() {
- // put your main code here, to run repeatedly:
- //monitor buttons
- button1.tick();
- }
- // This function will be called when the button1 was pressed 1 time (and no 2. button press followed).
- void click1() {
- Keyboard.press(KEY_LEFT_CTRL);
- Keyboard.press(KEY_LEFT_ALT);
- Keyboard.press(KEY_LEFT_SHIFT);
- Keyboard.release(KEY_LEFT_CTRL);
- Keyboard.release(KEY_LEFT_ALT);
- Keyboard.release(KEY_LEFT_SHIFT);
- delay(100);
- Keyboard.press(KEY_LEFT_ALT);
- Keyboard.press('A');
- Keyboard.release(KEY_LEFT_ALT);
- /*
- // this is generally not necessary but with some older systems it seems to
- // prevent missing the first character after a delay:
- DigiKeyboard.sendKeyStroke(0);
- // Type out this string letter by letter on the computer (assumes US-style
- // keyboard)
- //DigiKeyboard.sendKeyStroke(0, MOD_SHIFT_LEFT | MOD_CONTROL_LEFT | MOD_ALT_LEFT);
- DigiKeyboard.delay(100);
- DigiKeyboard.sendKeyStroke(KEY_A, MOD_ALT_LEFT);
- */
- } // click1
- // This function will be called once, when the button1 is pressed for a long time.
- void longPressStart1() {
- Keyboard.press(KEY_LEFT_CTRL);
- Keyboard.press(KEY_LEFT_ALT);
- Keyboard.press(KEY_LEFT_SHIFT);
- Keyboard.release(KEY_LEFT_CTRL);
- Keyboard.release(KEY_LEFT_ALT);
- Keyboard.release(KEY_LEFT_SHIFT);
- delay(50);
- Keyboard.press(KEY_LEFT_ALT);
- Keyboard.write('Q');
- Keyboard.release(KEY_LEFT_ALT);
- delay(50);
- Keyboard.write(KEY_RETURN);
- /*
- // this is generally not necessary but with some older systems it seems to
- // prevent missing the first character after a delay:
- DigiKeyboard.sendKeyStroke(0);
- // Type out this string letter by letter on the computer (assumes US-style
- // keyboard)
- DigiKeyboard.sendKeyStroke(0, MOD_SHIFT_LEFT | MOD_CONTROL_LEFT | MOD_ALT_LEFT);
- DigiKeyboard.delay(50);
- DigiKeyboard.sendKeyStroke(KEY_Q, MOD_ALT_LEFT);
- DigiKeyboard.delay(50);
- DigiKeyboard.sendKeyStroke(KEY_ENTER);
- */
- } // longPressStart1
Add Comment
Please, Sign In to add comment