Example script for OBS with usb keypad (homemade streamdeck)

How can be this controlled in that simulator? Can HIDmacros be used with this application?
Post Reply
Posts: 4
Joined: 31 Dec 2017, 14:59

Example script for OBS with usb keypad (homemade streamdeck)

Post by mrKaine83 » 01 Jan 2018, 15:40

I'm setting up an external keypad to use with OBS. I tried using HID macros, but ran into the issue where the keypress occurs too fast for OBS to detect it when not the active window.

So now I need to use LUA macros, however I don't have scripting experience. I can see from another thread I found I'll need to use something like this:

Code: Select all

lmc_send_input(16, 0, 0) -- press shift
lmc_send_input(65, 0, 0) -- press A
lmc_send_input(65, 0, 2) -- release A
lmc_send_input(16, 0, 2) -- release shift
but I can't see how I tell it to listen for a specific keypress (from a specific keyboard). I've looked at many threads and youtube videos, but am unable to figure this out for myself.

Would someone be kind enough to post for me a complete example script that listens for a key on a specific device, then as above presses a key, pauses and releases the key? Then I can use it as a template to create for each key on my keypad.

Thank you in advance.
Last edited by mrKaine83 on 01 Jan 2018, 16:16, edited 1 time in total.

Posts: 4
Joined: 31 Dec 2017, 14:59

Re: Example script please?

Post by mrKaine83 » 01 Jan 2018, 16:15

(edited this post to clarify & replaced with updated code)

I have surprised myself and figured it out!

For others who might make use of this, my complete script is as follows:

Code: Select all

lmc_print_devices() 									//List attached keyboards
lmc_device_set_name('streamdeck','54EFE92') 				//Give the keyboard a friendly name

lmc_set_handler('streamdeck', function(button,direction)		//Listen for key presses from named keyboard
  if (direction == 1) then return end 						//ignore button release
  if (button == 13) then								//if button is enter
    lmc_send_keys('^{ENTER}', 50)						//send key combo ctrl + enter then pause for 50ms

    elseif (button == 97) then
    lmc_send_keys('^{NUM1}', 50)

    elseif (button == 98) then
    lmc_send_keys('^{NUM2}', 50)

    elseif (button == 99) then
    lmc_send_keys('^{NUM3}', 50)

    elseif (button == 100) then
    lmc_send_keys('^{NUM4}', 50)

    elseif (button == 101) then
    lmc_send_keys('^{NUM5}', 50)

    elseif (button == 102) then
    lmc_send_keys('^{NUM6}', 50)

    elseif (button == 103) then
    lmc_send_keys('^{NUM7}', 50)

    elseif (button == 104) then
    lmc_send_keys('^{NUM8}', 50)

    elseif (button == 105) then
    lmc_send_keys('^{NUM9}', 50)

    elseif (button == 111) then
    lmc_send_keys('^{NUMDIVIDE}', 50)

    elseif (button == 106) then
    lmc_send_keys('^{NUMMULTIPLY}', 50)

    elseif (button == 109) then
    lmc_send_keys('^{NUMMINUS}', 50)

    elseif (button == 107) then
    lmc_send_keys('^{NUMPLUS}', 50)

    elseif (button == 8) then
    lmc_send_keys('^{BACKSPACE}', 50)

    elseif (button == 110) then
    lmc_send_keys('^{NUMDECIMAL}', 50)

    elseif (button == 96) then
    lmc_send_keys('^{NUM0}', 50)
I found the keyboard ID number (for me 54EFE92) by running lmc_print_devices() and copying the part just before '&0&0000'. It might be helpful to unplug your main keyboard when you run it to identify which is the numpad.

I found the key numbers (i.e. enter is 13, num1 is 97) by running HID macros and observing the numbers in the 'event' field' when you press a key.

This script does all the usable keys on a num pad. To add more keys simply copy & paste one of the 'elseif' statements and replace the key number and key combo to send.
Last edited by mrKaine83 on 06 Mar 2018, 18:03, edited 2 times in total.

Posts: 1
Joined: 13 Jan 2018, 23:11

Re: Example script for OBS with usb keypad (homemade streamdeck)

Post by TuecerPrime » 13 Jan 2018, 23:18

I'm having the exact same issue myself, and don't understand your post sadly.

Is there a way you could assist me (and others) with a more detailed walkthrough?

Posts: 4
Joined: 31 Dec 2017, 14:59

Re: Example script for OBS with usb keypad (homemade streamdeck)

Post by mrKaine83 » 06 Mar 2018, 17:32

Apologies for the long delay in replying.
I actually put together a video tutorial that should hopefully clear things up.

Site Admin
Posts: 550
Joined: 01 Nov 2010, 13:00
Location: Prague, Czech republic

Re: Example script for OBS with usb keypad (homemade streamdeck)

Post by admin » 07 Mar 2018, 09:36

Nice one.
Just 2 small comments:
- the "number" part from device id doesn't have to be from that specific place. It can be any part of that long value which is unique between other values (for other keyboards)
- you don't need HidMacros to get the key number. I believe those number are virtual key codes so you can find it at web (google it) or the easiest way is to log the value in script even if it is not used by the code. Something like the else part here: https://github.com/me2d13/luamacros/blo ... kstart.lua. Or just similar print command at the beginning of callback handler
Petr Medek
LUAmacros author

Post Reply