Jump to content

Use 2nd keyboard as macro keyboard w/ NotEnoughHotkeys and AutoHotkey

So, I recently decided to set up a 2nd keyboard for macros, and while there's already a lot of documentation on the topic (I recommend Taran's GitHub page on it), I didn't find any on NotEnoughHotkeys, which is actually a really good, easy to use (and open source too!) alternative to LuaMacros (albeit a bit less powerful), so I decided to post my findings here for anyone who might find them useful.

 

As said in the title, my main focus will be integration of this program with AutoHotkey (AHK), since there's already plenty of documentation, tools, and user-made macros for it already out there so it's really practical to make whatever tool you're using just trigger AHK scripts. It's worth adding that I'm a begginer with AHK, so I won't go into too much detail with it.

 

Short tutorial:

TL,DR; in case you just want the gist of it:

  1. Download and run NotEnoughHotkeys
  2. Identify the keyboard you want to use as a macro keyboard in it
  3. Separately, create an AHK script (that will be the performing the actual macros) with roughly the following structure:
    ; Things that go at the top of most ahk scripts like SendMode
    
    var := A_Args[1] ; Saves the (first) command line parameter passed when the script was called in a variable
    
    if (var = "action1"){
    	; Your macros...
    }
    else if (var = "action2"){
    	; Another macros...
    }
    
    ; The rest of your macros...
  4. Inside NotEnoughHotkeys, create a new macros set to launch process, with process to launch set to the AHK script you created in the previous step, and arguments set to some string you want to use to identify it.
  5. In the AHK script,  for it to run whatever set of actions you want when you press the key you just designated, just put the same you just put as a command line argument inside the corresponding if (i. e., if you want to set a hotkey to mute your mic, you might put muteMic as the argument on the macros in NotEnoughHotkeys, and in the AHK script you'd have if(var = "muteMic"){; macro code...}).
  6. Repeat for as many hotkeys as you need.

IMPORTANT: in your AHK script, you shouldn't have anything that keeps the script running (like an actual hotkey with {key}::), because that might cause several instances of the script to be open (you can add #SingleInstance force at the top just to be sure).

After the long tutorial I go for some pros and cons of this method.

 

Long Tutorial:

So, the initial setup of NotEnoughHotkeys (NEH from now on) is really easy (and the reason I like this program so much), you just download it from its GitHub page (you can click on newest release and download the .zip if you don't understand all that building stuff on the main page), extract the .zip, and launch it, it's an standalone app so no install needed. You should launch it as an admin since not doing so might cause issues, but the program warns you if you don't do it anyways so it's easy enough to remember.

 

You will be greeted with a window like this (obviously without the macros already created):

 

image.png.321748eb1f8de75fe2a8da995e50bdd6.png

 

Pretty self explanatory UI: Click on Select and then press any key on the macro keyboard to identify it as such, the + is for creating a new macro, the trash bin for deleting an existing one, the pencil to edit one, the enabled tickbox lets you turn it on/off without needing to close the app, settings opens a little window with just one setting (launch at startup), and quit and minimize to tray do as they say. The i gives you some info on the kayboard you selected as a macro keyboard, but I haven't needed it so far so don't worry too much about it.

 

The create/edit macro window is also easy enough to understand:

 

image.png.dd46b0a715a42b7d9b323da377aa979a.png

 

Do keep in mind that you need to press the hotkey on your main keyboard, and that currently NEH only supports single key hotkeys unfortunately.

This is good for typing strings and... not much else really. NEH doesn't currently suport modifiers (ctrl, shift, etc.) either, so it's very limited. So making it fire macros programmed with AHK (like with the LuaMacros to file in disk to AHK hackery) is much more useful. For that I used the Launch Process option for macros.

 

(Sidenote: Send Single Keycode is pretty self explanatory (sends a single keypress), and I haven't used Send Http Request yet and I'm not really sure how it works either, so if anyone wants to elaborate on that very much appreciated!)

 

So, the Launch Process tab looks like this:

 

image.png.2f1f8bfc2228099b3f4100f15fdb636a.png

 

Path being the path of the process you want to launch, Arguments the command line arguments the program is going to launch with, and Launch Path the directory in with the process is going to launch (you can generally leave this blank, as it says it'll auto-fill it with the path for the process directory when you save it).

This is useful itself to have, say, an open google key, but, you can also launch an AHK script with this method.

 

Now, normally AHK schipts look something like this:

(I'm not going too much into AHK syntax and programming, there's already plenty of resources elsewhere for that)

 

; Stuff that goes at the top of most scripts (SendMode, etc)

f1::
Send, You pressed F1!
; whatever else the hotkey does
return

; more hotkeys...

 

When you run that, it doesn't actually does anything, rather, it waits for the designated hotkeys to be pressed in order to execute the macro, but we want to execute the macro when the script is executed, since we are calling the script with NEH rather than pressing a key. This can be achieved simply by ommiting the hotkey part and just putting the code (note that this will run all the code).

Now, you could just, say, have each macro call its own separate script, but that can get out of control really quickly. That's when the Arguments box in NEH comes into play!

AHK scripts can be called with arguments from the command line. Inside the scripts, these arguments are located within the variable A_Args (which is an array). Note that the first parameter is located in A_Args[1]. Since you can call the script with arguments from NEH, you can use this to let the script know what key you pressed, for example:

action := A_Args[1]

if (action = "muteDiscord"){
	Send, ^+m
    return
}
else if (action = "applyCoolPremiereTransition"){
	; Whatever this macro does
    return
}

 

Then, in NEH, you can call this script with the argument muteDiscord when you press a key and call it with the argument applyCoolPremiereTransition when you press another.

You even can use various arguments to organize your script better if you want, like:

application := A_Args[1]
action := A_Args[2]

if (application = "Premiere"){
	if (action = "transition1"){
    	; Your premiere macros
        ...
    }
}

else if (application = "Photoshop"){
	if (action = "filter1"){
    	; Your photoshop macros
        ...
    }
}

And then you just put Premiere transition1 in the arguments box in NEH (arguments separated by spaces).

 

And with this, you can basically assing a macro to every key of the 2nd keyboard. For more information on passing command line arguments to AHK scripts, you can check the AHK help manual (Usage and Syntax -> Scripts (misc) -> Passing Command Line Parameters to a Script).

 

Pros and cons of this method:

 

Pros:

  • Really easy to set up.
  • Easy to manage what key does what action.
  • Great versatility, since AHK is a very powerful macroing tool.
  • Completely free, you just need to have an extra keyboard around and you can set it up.
  • Entirely open-source solution.

 

Cons:

  • Can't use modifier keys (listed as being worked on in GitHub).
  • Can't set macros for more than one keyboard (listed as being worked on in GitHub).
  • You need to identify the macro keyboard everytime you restart.
  • Can be a bit of a pain to manually set a lot of macros.

 

Extras:

 

Setting F13-24 hotkeys for discord (and other problematic programs):

One of the known issues listed in the GitHub page for NEH is that some programs still get the 2nd keyboard input. The only offender I've found thus far is Discord when you're in the keybinds settings. So, if you, for example, set a macro for muting your mic and assing it to the A key, when you go to Discord to assign it and press A on the macro keyboard, Discord will record the A press instead of the macro. You can get around this by just inputing the macro manually for the setup (you'd only had to do it once anyways), since after that it works fine, but if you want to use keys that aren't phisically present in your keyboard (like F13-24), it's a bit trickier to set it up.

What I ended up doing was the following:

  • I wanted to assing mute to shift + F13
  • I went into NEH, opened the create macro window, and went to the Send single keystroke tab
  • Selected the F13 key
  • Went into Discord keybinds settings
  • Clicked the Send keystroke now button in NEH
  • went back into Discord, clicked edit keybind, and held shift until the 5 second timer for NEH to send the keystroke ran out.
  • Discord recorded the kaybind properly.

If you need to do something more complex, you can probably whip up a temporary AHK script to input the combination if you need it.

 

Easily replacing the LuaMacros file + F24 method with NEH:

If you already have the LuaMacros thing set up and don't want to re-write your whole AHK script to fit this, you might not need to! You can just set NEH hotkeys to fire a script that writes to a file in disk and then press the F24 key. I haven't personally tested it, but it should be equivalent to the old LuaMacros setup and thus require zero modification of the original AHK script (but you'd still need to write that auxiliary script to write the file and press f24). It's a bit more convoluted tho.

 

THE END

Hope this is useful to someone out there. This is my first time writing a tutorial like this so any feedback is appreciated. Have a nice macroing y'all =)

image.png

Link to comment
Share on other sites

Link to post
Share on other sites

  • 7 months later...

OH MY GOD THANK YOU SO MUCH. ive been spending hours trying to find a easier way to macro a keyboard and you just saved me

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×