Macropad for Keyboard Shortcuts

by moderntimesmelon in Circuits > Arduino

16039 Views, 283 Favorites, 0 Comments

Macropad for Keyboard Shortcuts

PXL_20220225_185546817.jpg

We're making a small macro keypad for some keyboard shortcuts. In this case, it is for Zoom video conferencing shortcuts for Windows. We'll program the keys to toggle mute/unmute microphone, raise/lower hand, and video on/off.

Supplies

PXL_20220225_171459177.jpg
pro micro.jpg

The board we're using to run this is a clone of an Arduino Pro Micro. You can use the official one, or a cheaper clone like I am. The important thing is that it is an atmega32u4 chip that is running it, so that you have native USB support. There are versions with a microusb connector (like I'm using), mini-usb, and usb-c. Any of those are fine for this project.

You need 3 switches - or buttons or keys. Any 2 pin normally open momentary switches will work - I've built this project with arcade buttons before too. For this write-up, I'm using some Gateron Brown switches.

Some hookup wire - I am using 26 gauge solid core wire, but you can use thicker or thinner, or you can use stranded instead of solid core.

Also needed: wire cutters/strippers, needle-nose pliers, solder, soldering iron, some kind of housing for the project (I'm using one I 3d printed), and appropriate USB cable (depending on pro micro version and available usb ports on computer)

Optional: hot glue, flux, insulator like liquid tape.

Mount the Switches

PXL_20220225_171532957.jpg
PXL_20220225_172131145.jpg

Install the switches in the housing. In my case, the mechanical switches go in 14mm x 14mm square openings in the lid. They fit in there pretty well, but I've found they can also pop-out when connecting the wires, so I fill the gaps with hot glue, but you don't have to. I just like to have it really solidly in there.

The stl files for the housing are attached if you want to 3d print them.

Cut and Attach the Wires

PXL_20220225_172114914.jpg
PXL_20220225_172131145.jpg
PXL_20220225_183201584.jpg

Each switch has 2 pins. One pin needs to be connected to Ground and the other to a pinhole on the Pro Micro. So, we're going to wire all the ground pins together to a single ground on the Pro Micro. Cut 3 shorter lengths of wire, and one longer one and strip one end of the wire insulation (see photos). The mechanical switches have rather small pins, so I find it best to use the needle-nose pliers to hook the ends of the wire and then wrap them around the pin a few times.

Solder the Switches

PXL_20220225_183435646.jpg
PXL_20220225_183439684.jpg

Optional step: use a Flux Pen on each of the pins/wrapped wires. Flux makes solder flow easier.

Now it's time to solder the wires to the pins. Best practice is to put the tip of the soldering iron on the pin/wire and touch your solder to it. But don't worry too much, just get some solder on there so the wires don't pull off.

Connect the Pro Micro

PXL_20220225_183954546.jpg
PXL_20220225_184130266.jpg
PXL_20220225_184230921.jpg

Adjust the length of the wires if needed and strip a small amount of insulation off the end of each one. You can connect the data wires to whichever pins you like really, but I tend to space them out - just my preference. I use pins 9, 6, and 3, and Ground.

Use those helping hands clip things if you have them or figure out a way to hold the Pro Micro with the wires in the right holes, and solder. Again, flux is helpful, but if you don't have it, you can still make the connection. This soldering is a little more sensitive because you don't want to burn the board and ruin it - so try to be quick applying the solder.

Clip the bits of wire that are left sticking out.

Optional: Reinforcement

PXL_20220225_184759774.jpg

I have found that especially with the MicroUSB versions of the Pro Micro clones that the connections of the usb port to the board is weak. It is often a failure point after plugging and unplugging several times. To help prevent this problem, a blob of hot glue will provide reinforcement. (The mini-usb version seems more solid, not sure about the usb-c version)

Connect the USB Cable

PXL_20220225_185105534.jpg
PXL_20220225_185116838.jpg

Connect the USB cable and close up the housing.

Program the Buttons

3LeoWin_Screenshot.png

Use the Arduino IDE to program the buttons: https://www.arduino.cc/en/software

You can either download and install the free IDE for your system, or you can create an account and use their online IDE with their small "agent" program to allow programming via USB.

For computer installation, please follow the instructions there for installation and setup. Then please install the OneButton library: https://www.arduino.cc/reference/en/libraries/onebutton/

If you are using the online IDE, you do not need to install the library.

Files with code for Zoom on Windows and Zoom on Mac are attached.

Below is the code for Zoom shortcuts on Windows.

Notes:

Anything after a // is a comment, as well as anything between /** */. Comments are not part of the program, just explanation.

OneButton library does most of the heavy lifting. When each button is setup, the built-in pull-up resistor is turned on, which is why there's no physical resistor in the circuit. The built-in resistor is sufficient.

You can easily change the keyboard press and release statements to whatever you need.

The delays are in milliseconds.

#include <Keyboard.h>   // https://github.com/arduino-libraries/Keyboard/blob/master/src/Keyboard.h
#include <OneButton.h>    // Library for button input functions, https://github.com/mathertel/OneButton

//setup buttons with OneButton
OneButton button1(
  9,          // Pin Number  (function: MUTE)
  true,       // Input is active LOW
  true        // Enable internal pull-up resistor
);
OneButton button2(
  6,         // Pin Number  (function: HAND)
  true,       // Input is active LOW
  true        // Enable internal pull-up resistor
);
OneButton button3(
  3,          // Pin Number  (function: VIDEO)
  true,       // Input is active LOW
  true        // Enable internal pull-up resistor
);


void setup() {
  button1.attachClick(button1click); // Set up button 1 for mute toggle function
  button2.attachClick(button2click); // Set up button 2 for hand toggle function
  button3.attachClick(button3click); // Set up button 3 for video toggle function

  Keyboard.begin(); //Init keyboard emulation
  Serial.begin(9600); // begin serial comms for debugging
}//end setup


// Check status of buttons in a continuous loop
void loop() {
  button1.tick();
  button2.tick();
  button3.tick();
} //end loop


/**
   Since Zoom version 5.8, short delays are needed so as not to change the visibility of the
   status bar at the bottom of the meeting, which is triggered by the ALT key
*/


// This function will be called when button 1 is pressed for more than 50ms and less than 300ms.
void button1click() {
  Serial.println("Pressing alt+a for Mute/Unmute");
  Keyboard.press(KEY_LEFT_ALT);
  delay(20);
  Keyboard.press('a');
  delay(10);
  Keyboard.release('a');
  delay(20);
  Keyboard.releaseAll();
}


// This function will be called when button 2 is pressed for more than 50ms and less than 300ms.
void button2click() {
  Serial.println("Pressing alt+y for Hand");
  Keyboard.press(KEY_LEFT_ALT);
  delay(20);
  Keyboard.press('y');
  delay(10);
  Keyboard.release('y');
  delay(20);
  Keyboard.releaseAll();
}


// This function will be called when button 3 is pressed for more than 50ms and less than 300ms.
void button3click() {
  Serial.println("Pressing alt+v for Video");
  Keyboard.press(KEY_LEFT_ALT);
  delay(20);
  Keyboard.press('v');
  delay(10);
  Keyboard.release('v');
  delay(20);
  Keyboard.releaseAll();
}

Finish Programming

The Pro Micro is a smaller version of an Arduino Leonardo, so to make programming easy, be sure to select "Arduino Leonardo" under Tools > Board > Arduino AVR Boards > Arduino Leonardo

Connect the USB cable to your computer, make sure your Arduino IDE sees it and is going to send it the programming correctly. Go to Tools > Port > select the correct one

Then you can compile it with the checkmark (or Sketch > Verify/Compile) or skip straight to Upload (Sketch > Upload).

Upload will first compile the program, and then send it to the board.

You should get a message saying it was successful and you're good to go!

Add some keycaps and you're ready to use your new Zoom shortcuts.