I want to use a USB keypad to control elements of Open Broadcaster Software.
This guide is good, but my script is very thorough. See key remapping.lua
Using LuaMacros ∞
The basics ∞
What you will be learning to do is:
- Learn about your second USB keyboard.
- Learn about all the individual keys of your second USB keyboard.
- Map each key to the key combination or LuaMacros function you wish to use.
-
Configure any other software you use to perform actions based on those key combinations.
- For example, if you press
1
on your second USB keyboard, you can have LuaMacros issuecontrol-alt-windows-F2
instead of the number1
, and then you can configure Open Broadcaster Software to transition to "scene 2" when it seescontrol-alt-windows-F2
.
- For example, if you press
--
- Get
key remapping.lua
- Get
learn keyboard.lua
- Get LuaMacros (direct download)
-
Unzip LuaMacros
- It is a "portable" program which does not need to be installed.
Learn your keyboard ∞
- Launch LuaMacros
- Remove your second USB keyboard
- Type
lmc_print_devices()
- Press the "play" triangle at the top of the window
- Insert your second USB keyboard
- Type
lmc_print_devices()
- Press the "play" triangle at the top of the window
- Note the new device which was added
- Open
key remapping.lua
with a text editor. -
Modify it to set
usb_device_code=
- For example:
\\?\HID#VID_13BA&PID_0001#8&BE46E30&0&0000#{884B96C3-56EF-11D1-BC8C-00A0C91405DD}
is
usb_device_code=BE46E30
- For example:
Learn your keys ∞
- Insert your second USB keyboard
- Open
learn keyboard.lua
with a text editor. - Launch LuaMacros.
- Copy the contents of
learn keyboard.lua
into the upper part of LuaMacros. - Press the "play" triangle at the top of the window.
-
Open
key remapping.lua
with a text editor.
Your goal is to:
1. Switch to LuaMacros.
2. Press a key on your second USB keyboard.
3. Edit key remapping.lua
to change one of the lines that looks like this:
elseif ( button == 106 ) then lmc_send_keys( '^>%#{NUMMULTIPLY}', 50 ) -- *
Notice the button == 106
. You will be changing that number.
4. Also change a line like the above to your preferred macro or action.
The above example means that when key 106 is seen, which is the forward-slash key on the USB numberpad, ^>%#{NUMMULTIPLY}
is output. That's <right-side-control>-alt-windows-<numberpad />
, which is an intentionally-unusual key combination. See List-of-Keys.md
for some help.
Some examples for launching a program:
- Launch the
calc
program withlmc_spawn( 'calc' )
-
Open a text file with
notepad
withlmc_spawn( 'notepad', 'C:\\test.txt' )
--
Go through steps 3 and 4 for every key on your USB keypad. It's likely that I've already set things up quite well in my example script.
Use ∞
1. Insert your second USB keyboard
2. Launch LuaMacros
3. Open your personalized key remapping.lua
file with a text editor.
Note that you may prefer to edit key remapping.lua
to remove (or comment-out by beginning those lines with --
) the bottom three lines:
lmc.minimizeToTray = true lmc_minimize() lmc_say( 'Launched' )
4. Copy the contents of your personalized key remapping.lua
file into the upper part of LuaMacros.
5. Press the "play" triangle at the top of the window.
It will launch, remapping your choice of keys to whatever you customized it to do.
6. Teach your software to notice those keystrokes.
Example: OBS Studio ∞
An example with OBS Studio:
- Launch LuaMacros
- Copy the contents of your personalized
key remapping.lua
file into the upper part of LuaMacros. - Press the "play" triangle at the top of the window.
- Launch OBS
- File > Settings > Hotkeys
- For any of your scenes, click inside the text area and then press the key on your second USB keyboard for macros.
- Once done, click
OK
at the bottom of the window to accept your new hotkey settings. -
Use OBS as usual, and you can press the keys on your second USB keyboard.
Alternatives ∞
I know there are other solutions, but LuaMacros has been the only solution I've really investigated, because it works.
Last updated 2023-07-19 at 23:53:44
Hello, thank you for let this tutorial here. I really apreciated.
I´m facing a issue. When I run the .lua my main keyboard stop working. If I unplug and plu it again, everthing works fine. Did you face or saw some issue like that? Thanks
Yes I've had issues like that. You have to be careful to only make code which refers to that one particular device.
To solve your problem, you will probably find better instructions here:
https://github.com/spiralofhope/shell-random/blob/master/live/LuaMacros/key%20remapping.lua
Also, instead of unplugging and re-plugging your keyboard, you can use your mouse to exit the program.
Hi! I wonder if one can use LuaMacros to swap keys, e.g. Caps Lock ⇔ Left Ctrl?
Thank you!
Definitely don't do that with LuaMacros. Check out AutoHotKey
https://blog.spiralofhope.com/?p=19853
These should get you going:
https://www.autohotkey.com/docs/v1/misc/Remap.htm (( was [[archive:https://www.autohotkey.com/docs/misc/Remap.htm|]] ))
https://www.autohotkey.com/boards/viewtopic.php?t=37117
https://www.autohotkey.com/board/topic/109238-turn-caps-lock-into-another-shift/
https://www.autohotkey.com/boards/viewtopic.php?t=64445
https://www.autohotkey.com/boards/viewtopic.php?t=10283
Thank you! While AutoHotKey works great, it seems to modify the behavior of all keyboards.
Do you have ideas to only swap keys on a specific keyboard? Thanks!
I suppose you're forced to use LuaMacros then.
Investigating a little, it looks like you'd have to remap the individual keys being depressed and released.
This post has a hint at the bottom:
http://www.hidmacros.eu/forum/viewtopic.php?f=6&t=4537&p=6138
I can't help any further than this, but please report back if you learn to program a solution!
Thank you very much! I tried the method in that post. I can use CapsLock to simulate Ctrl presses and releases (see code below), but the original CapsLock events are not blocked. It seems to be a limitation of LuaMacros: https://github.com/me2d13/luamacros/issues/26
Anyway, thank you!