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
mrKaine83
Posts: 3
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_sleep(50)
lmc_send_input(65, 0, 0) -- press A
lmc_sleep(50)
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.

mrKaine83
Posts: 3
Joined: 31 Dec 2017, 14:59

Re: Example script please?

Post by mrKaine83 » 01 Jan 2018, 16:15

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_device_set_name('streamdeck','54EFE92') 

lmc_set_handler('streamdeck', function(button,direction)
  if (direction == 1) then return end
  if (button == 13) then
    lmc_send_input(17, 0, 0) -- press ctrl
    lmc_sleep(50)
    lmc_send_input(16, 0, 0) -- press shift
    lmc_sleep(50)
    lmc_send_input(13, 0, 0) -- press enter
    lmc_sleep(75)
    lmc_send_input(17, 0, 2) -- release ctrl
    lmc_send_input(16, 0, 2) -- release shift
    lmc_send_input(13, 0, 2) -- release enter 
    end
  end
  )
    
I found 54EFE92 by running lmc_print_devices() and copying the part just before '&0&0000'
I found the key numbers (i.e. enter is 13,0,0) by running HID macros and observing the numbers in the top right when you press a key

This script only does one key. to add more keys, copy from the second 'if' (inclusive) up to the first 'end' (exclusive) and paste it before the first 'end' adding an 'else' at the start. So for 2 keys, the code is:

Code: Select all

lmc_device_set_name('streamdeck','54EFE92')
lmc_print_devices()

lmc_set_handler('streamdeck', function(button,direction)
  if (direction == 1) then return end
  if (button == 13) then
    lmc_send_input(17, 0, 0) -- press ctrl
    lmc_sleep(50)
    lmc_send_input(16, 0, 0) -- press shift
    lmc_sleep(50)
    lmc_send_input(13, 0, 0) -- press enter
    lmc_sleep(75)
    lmc_send_input(17, 0, 2) -- release ctrl
    lmc_send_input(16, 0, 2) -- release shift
    lmc_send_input(13, 0, 2) -- release enter

    elseif (button == 97) then
    lmc_send_input(17, 0, 0) -- press ctrl
    lmc_sleep(50)
    lmc_send_input(16, 0, 0) -- press shift
    lmc_sleep(50)
    lmc_send_input(97, 0, 0) -- press 1
    lmc_sleep(75)
    lmc_send_input(17, 0, 2) -- release ctrl
    lmc_send_input(16, 0, 2) -- release shift
    lmc_send_input(97, 0, 2) -- release 1
  end
end
)

TuecerPrime
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?

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 3 guests