A macro keypad can be used to perform certain actions or functions on your computer and can be really useful with certain applications, such as video editors or games.
A lot of applications have hot keys for quickly performing actions, but sometimes it's hard to remember the button combination of each command, but that is where a macro keypad comes in. They can be programmed in basically any button combination or sequence so it can be a really powerful tool.
My main use for mine is for controlling OBS, the software I use for recording videos and for streaming. It allows me to easily swap between scenes or to enable to disable certain elements of scenes.OK, I'm going to make a bold claim here, this is the simplest DIY macro keypad you can build! If you know of a simpler one please link it to me, because I haven't found one yet.It uses only 2 components and no special boards need to be installed for Arduino so it really can't get any easier!
The Arduino Pro Micro supports emulation of HID (Human Interface Devices, aka your keyboard an mouse) so it's perfect for this kind of a project.We will also be using a 4x4 Keypad because it's cheap, has 16 buttons and is really simple to wire up
I made a video on this topic if you want to check it out!
This couldn't be any easier!
The Keypad Matrix plugs directly into the 8 GPIO on the bottom right of the Pro Micro, the ones labaled GPIO2 - GPIO 9. The wire on the left of the keypad connects to GPIO2
And that's it, didn't I tell you this was simple!
If you are interested in how the keypad works, I'll give a quick explanation of it here. If you are not interested, just skip this step!
Each row and column are connected to a GPIO pin of your arduino. The 4 row pins are set as output and the 4 column pins are set as inputs.The Arduino will cycle through the row pins one by one, setting each one to be high, while the other rows are low. Will each row is set as high, it will read each one of the column pin. If one of the column pins is high, you can tell which button was pressed as you now know the column row that was pressed.
We won't need to worry about this because we are going to use a library to look after this for us!
First thing you will need is the Arduino IDE, which you can get from here if you don't have it. It is pretty straight forward to setup, but if you need more instructions or guidance, I would recommend checking out the Arduino Class by Becky Stern
You then will want to grab the code for this project from my Github. Click the clone or Download button over on the right hand side of the page and click the "Download Zip" button.
Extract the zip and open it with the.ino file with the Arduino IDE.
Before we can upload this sketch to the board, we first need to install the Keypad library for interfacing with the matrix keypad.
To install this, click on Sketch -> Include Libraries -> Manage libraries
When that loads, search for "keypad" and scroll down to the one written by Mark Stanley and Alexander Brevig. Click install.
You are now ready to upload the sketch! We just need to configure the Arduino IDE for the correct board and port.
In the Tools menu, go down to Board and select Arduino/Genuino Micro
In the same Tools menu, go to Port and select the com port that has (Arduino/Genuino Micro) after itYou can now click the upload button and it should program your device!
You have a fully functioning macro keypad at this stage so If you don't care how the code works, skip this step.
Keypad Library config
In the first image you will see the configuration of the keypad library. If your keypad had more or less rows or columns you would change it here.The "keys" array lets the library know what character it should return to you when a button is pressed. So if your matrix had the letters of the alphabet instead of numbers you could change it here to match. It doesn't really matter what is in here once you react to the button press appropriately (more about this below)The next thing we have is the pin definition for the rows and columns, these are already set up correctly for the wiring that we did earlier.And finally there is the constructor where we initialize the keypad library with all the config.
Reading the button presses
In the loop, the sketch gets the pressed key off keypad library, what is returned is one of the character that we defined in the "keys" array that corresponds to the same position as the button that was pressed. So if key is true (is set at all) we use a switch statement to check which button was pressed and perform whatever action we want to do with it. This is why it's not really important whats in your keys array, once you perform this check.
Once the button is checked, it will call the SendMacroCommand.
SendMacroCommand is the the method that all the options call. It takes in one parameter as a key, by default this is f1-f12 and then a, b, c and d.This method basically emulates holding down the following buttons
- and the key that is passed in as param
These buttons will not be released til we specifically say for it to. We do this at the end of the loop.
My main use case for this device is to use it with hotkeys in OBS (Open Broadcast Studio, its a software mainly used by streamers, but useful for capturing any video on your PC). This can be useful for changing scenes or enabling elements in your selected scenes.
In OBS, open the settings menu and then the hotkeys section.
Scroll down to the option that you want to control with your macro keypad and click in the white box. The next button you press will be the command associated with this action, so use your macro keypad to press whatever button you want to control this action.
To show how you can use it for more general commands and shortcuts, you can very easily make the ultimate stackoverflow keyboard, or one that is able to copy and paste.The command for copy is CTRL + c and the command for paste is CTRL + p
To add this to the keyboard, replace the call to the SendMacroKeypad method in one of the button press sections and replace it with the code in the image above. As before it will be as if both of these keys are held down til the release is called at the end of the loop.
Another pretty cool thing you can do with this setup is instead of just pressing buttons, you can simulate typing out a message. A good use case for this might be a custom quick chat keyboard for games.
The command for typing out a message is either keyboard.print. keyboard.println also works, its the same but just with a new line character at the end.
You can see in the above image an example of using it.
Under option 3, it will just type out the message straight away
Under option 4, it will first press the t button (this enables chat in a lot of games) and then types out the message. You may find you need to add a delay between the pressing of the t and typing the message to allow the game time to bring up the chat screen.
Hopefully you found this useful! I think there are a lot of possibilities with a device like this and hopefully this provides a good introduction to using HID commands on your Arduino Pro Micro.
What would you use a macro keypad for?
Have you seen any simpler Macro Keypads!?
If you have any questions feel free to ask!