DIY Macro Keyboard

Introduction: DIY Macro Keyboard

With more and more people doing quite intense work on their computers and getting into streaming. You might have wanted to improve your workflow on your computer if so you might have looked at getting some sort of secondary keyboard, maybe a Streamdeck to automate some of those more repetitive tasks on your computer, but a product like the Streamdeck is 150 dollars on amazon (At the time of writing this).

What if I told you that you could make any old Keyboard or Numpad into a fully customizable Macro keyboard. No additional hardware needed (Other than a keyboard of cause), and only for the cost of the Keyboard. Sounds cool right. Let me follow you through. All you need is a little bit of coding knowledge, a bit of patience and a keyboard.

Don't let the coding scare you. It won't be very difficult.

CREDITS

I did not myself come up with this method of setting up a second keyboard for macros. I want to give full credit to Tom Scott and TaranVH.

TaranVH/2nd-keyboard

The Art of the Bodge: How I Made The Emoji Keyboard

I modified their ideas and code to work for my liking.

Supplies

A keyboard

Step 1: Install the Necessary Programs

You might know that if you plug 2 keyboards into windows, windows won't be able to distinguish between them, therefore we have to get a little creative.

LuaMacros - Download

To distinguish between the 2 keyboards we will be using a piece of software named LuaMacros. LuaMacros was made for building flight simulators and can, therefore, differentiate between many keyboards.

Autohotkey - Download

To set up the macros that will make your life easier we will be using Autohotkey. A scripting language for creating powerful macros.

The code from my GitHub repository - Download

You will find all the files needed in this project on my GitHub page. Just click the green button and download the files. It helps to know where you save the folder you get when you click download on GitHub as It will help you later.

Step 2: Get You Keyboard ID

Even though Windows can't differentiate between keyboards each keyboard does have an ID. We will need this ID to tell LuaMacros which keyboard is our MACRO keyboard.

To find this ID open Luamacros and open the file Get_key_codes.lua -The file will be in the folder you downloaded from GitHub

When you have opened the file click the little blue triangle in the top to run the program. You will be asked to press a button on the keyboard you wish to turn into a MACRO keyboard

The program will then output a list of all connected devices. Something like what you see in the images above: In my case, you can see I have two devices connected. MACROS is the device you just identified by pressing a key on your secondary keyboard.

To the right of MACROS, we have a long string, This is a combination of the device type and id. My secondary keyboard has the id: PID_0745 you find the id between the 2 first &. Look at the image above

Note down your keyboard id. You will need it at step 3.

Step 3: Configure File: 2nd_keyboard.lua

Open LuaMacros and open the file 2nd_keyboard.lua - the file can be found where you found Get_key_codes.lua
Now find the line:

local kbID = 'PID_0745'

and replace my id (PID_0745) with the id you found in step 2. This is to tell LuaMacros what keyboard to listen for. Take care not to change anything else on the line.

Step 4: Try It Out

You should now be all set up and ready to run both the LuaMacros file and the Autohotkey file.

To do this first open the file 2nd_keyboard.lua in LuaMacros and click the little blue triangle.
Now right-click the file Main.ahk in file explorer and click run script.

You should now be able to click the key "1" on your second keyboard and see notepad opening. If this is the case congrats, you have fully set up your macro keyboard.

In the next step, we will look at how to configure your own macros


If it doesn't work here are some troubleshooting steps:

  1. Check that you did not accidentally change anything else in the code

  2. Check that you replaced my keyboard id with your correct keyboard id

  3. Try another keyboard

Step 5: Make Your Own Macro

Explanation

When LuaMacros detects that you have clicked a key on the macro keyboard, it writes down which key was pressed in the file key.txt it then presses F24. F24 is a key in windows that is not on your keyboard. When AutoHotkey. detects that F24 has been pressed it read the file on does the matching macro
Everything below line

 f24:: 

until the line

return 

is what AutoHotkey will do when F24 is pressed

The first thing Autohotkey will do when F24 is pressed is to read what is in the file key.txt. This happens on line 37.

I have then made a macro that will be activated if the output of the file is the key "1". If I click 1 on my Macro keyboard Notepad will open. (Line 41 - 43)

The next thing you can see is that if I press "q" on my keyboard Alt will be pressed down then F4 will be pressed then Alt will be released. This is like taking your finger hold down Alt then press f4 and then release Alt.
This key combo will close any active window in Windows

Make your own

You can keep adding macros like this by continuing the pattern. To add a new macro write

else if (ouput == Main_keys["whatever key you want in lowercase"])

	and then write what you want Autohotkey to do below it.

You can also use keys on the Numpad by writing

else if (ouput == Numpad["whatever key you want in lowercase"])

	and then write what you want Autohotkey to do below it.

For example, you can send keys by using the send command.

If I, for example, wanted my keyboard to type "This I awesome" When I click the "a" key I would add

else if (output == Main_keys["a"])

	Send, This is awesome

You will also see that I have added some macros for the Numpad keys. Every key on the Numpad has been assigned an emoji. (Make sure you haven't clicked Numlock as this will change the key codes)

Further help

If you want to learn how to make some really powerful macros check out the Autohotkey documentation
There is also plenty of help to get on the internet.

Good luck.

First Time Author Contest

Participated in the
First Time Author Contest

Be the First to Share

    Recommendations

    • Maps Challenge

      Maps Challenge
    • Metal Contest

      Metal Contest
    • Backyard Contest

      Backyard Contest

    2 Comments

    0
    jokocc
    jokocc

    Question 2 months ago on Step 5

    need help here, I connect a USB keyboard to laptop to become the second keyboard.
    after the second step, I can get the keyboard ID (oddly there are two lines of identical ID):<unassigned> : \\?\HID#VID_0C45&PID_5004&MI_01&COL01#8&29AA755&0&0000#{884B96C3-56EF-11D1-BC8C-00A0C91405DD} [344656105] : keyboard
    MACROS : \\?\HID#VID_0C45&PID_5004&MI_00#8&26BDBCD4&0&0000#{884B96C3-56EF-11D1-BC8C-00A0C91405DD} [262475895] : keyboard
    <unassigned> : \\?\ACPI#MSFT0001#4&2977C4B6&0#{884B96C3-56EF-11D1-AC8C-00A0C91405DD} [65605] : keyboard

    (I have checked, the ACPI is the onboard laptop keyboard)

    when I use it (PID_5004) on the third step (2nd_keyboard.lua), it won't trigger the function lmc_set_handler('MACROS' ,function(button, direction)

    initially I though the file write access is the problem, but the function write_to_file can be triggered manually without problem.

    any suggestions? thanks

    0
    paul.b.deichmann
    paul.b.deichmann

    Question 3 months ago on Step 5

    Hi! Super helpful, thank you for building this.

    Can we build our own macros with multiple actions lines? Like,
    Run, target
    Send, target

    So I could open chrome, then send it text to put in the URL, for example?

    Thank you!