Big Issue, Lua doesn't work when OBS is in the focus

Announcements, questions
Post Reply
4Sol
Posts: 3
Joined: 23 Sep 2020, 19:02

Big Issue, Lua doesn't work when OBS is in the focus

Post by 4Sol » 23 Sep 2020, 19:12

Hello there!

I actually have 2 problems:

1. When OBS is in FOCUS Lua doesn't work.
E.G. I set NUM5 to be ^+F1, but when OBS is in the FOCUS triggering Numpad's NUM5 gives just a regular NUM5 value of 5.
Like as I did this on the main keyboard. But If I press NUM5 out of OBS focus it would trigger correct combination of ^+F1.

How to solve it?
How to make OBS/Win to do not "see" NUM5 when you press it on the Lua keyboard?

2. NUM5 is NUM5.
When you use Lua NUM5 (^+F1) OBS/Win understand it as NUM5 and only then as ^+F1
So if you have a hotkey on the NUM5 of your main keyboard and you set your extra NUM5 to be ^+F1 - OBS will execute NUM5 and then ^+F1, when you trigger Extra NUM5.

Any solution?

This 2 problems existing together and I would appreciate for any feedback.

Thank you!

Code: Select all

lmc_device_set_name('streamdeck','12E34091')
lmc_print_devices()
lmc.minimizeToTray = true

lmc_set_handler('streamdeck', function(button,direction)
  if (direction == 1) then return end
  if (button == 13) then   

    elseif (button == 101) then                        -- 5
    lmc_send_keys('^+{F5}', 50)     

admin
Site Admin
Posts: 735
Joined: 01 Nov 2010, 13:00
Location: Prague, Czech republic
Contact:

Re: Big Issue, Lua doesn't work when OBS is in the focus

Post by admin » 24 Sep 2020, 08:02

I don't have OBS (even don't know what it is) but by the description provided I would say it reads keyboard directly so blocking of original key doesn't work in this application. There's nothing I can do about it. Some explanation is here: https://github.com/me2d13/luamacros/wik ... -keyboards
Petr Medek
LUAmacros author

4Sol
Posts: 3
Joined: 23 Sep 2020, 19:02

Re: Big Issue, Lua doesn't work when OBS is in the focus

Post by 4Sol » 24 Sep 2020, 09:14

admin wrote:
24 Sep 2020, 08:02
I don't have OBS (even don't know what it is) but by the description provided I would say it reads keyboard directly so blocking of original key doesn't work in this application. There's nothing I can do about it. Some explanation is here: https://github.com/me2d13/luamacros/wik ... -keyboards
Thank you for the answer.
All the idea behind using Lua with extra Num Pad is to build a stream deck. (to change scenes in OBS, trigger some gifs in OBS, sounds, etc.)

I guess the only solution will be to buy a streamer deck, with a custom software which will program "empty" buttons to what you need. Looking like this:
Image
It would be great if windows had a bigger amount of input numbers. Like F20, F21, F22 ... but hidden

Anyway it's too expensive and unavailable in my country.

BTW OBS (Open Broadcaster Software) is a streaming software. Looking like this:
Image

The other solution will be to buy a QMK keypad, like this one:
https://aliexpress.ru/item/4000510880374.html
But I'm too stupid to programme all the stuff and I'm not even sure it will work correctly.

foggydude
Posts: 1
Joined: 06 Oct 2020, 12:50

Re: Big Issue, Lua doesn't work when OBS is in the focus

Post by foggydude » 06 Oct 2020, 12:55

I have the opposite problem

i have a second numpad and with luamacros i have remapped those keys to function keys (f13-f24 and CTRL+alt+f3 etc).
In obs i have set those keys to trigger scene switches. but

- if obs is infocus = it works
- if obs is out of focus = it does not work

NB: the leys on my other keyboard ( or if i disable luamacros) it also works when obs is out of focus. how to solve?

Code: Select all

lmc.minimizeToTray = true
lmc_minimize()


--lmc_print_devices()   -- get the ID of the second keyboard from the stack that this line creates
lmc_device_set_name('MACROS1', "ID_1010") -- substitute the ID you have found here
-- lmc_assign_keyboard('MACROS1') -- if Lua doesn't work try adding this line

-- define callback for whole device, assign each key of the keyboard to an imaginary key (usually, keyboards have F1-F12, so we start assigning keys to F13)
lmc_set_handler('MACROS1',function(button, direction)
if (direction == 1) then return end  -- ignore down; if you want to be able to type the original letters as well with the secondary keyboard, remove this line
  if     (button == 45) then lmc_send_keys('{F13}')
 elseif (button == 35) then lmc_send_keys('^x')
  --elseif (button == 35) then lmc_send_keys('{F14}')
elseif (button == 40) then lmc_send_keys('^c')
  --elseif (button == 40) then lmc_send_keys('{F15}')
elseif (button == 34) then lmc_send_keys('^v')
  --elseif (button == 34) then lmc_send_keys('{F16}')
  elseif (button == 46) then lmc_send_keys('{F17}')
  elseif (button == 13) then lmc_send_keys('{F18}')
  elseif (button == 37) then lmc_send_keys('{F19}')
  elseif (button == 12) then lmc_send_keys('{F20}')
  elseif (button == 39) then lmc_send_keys('{F21}')
  elseif (button == 8) then lmc_send_keys('{F22}')
  elseif (button == 36) then lmc_send_keys ('{F23}')
  elseif (button == 38) then lmc_send_keys('{F24}')
  elseif (button == 33) then lmc_send_keys('^+{F15}')
  elseif (button == 107) then lmc_send_keys('^+{F16}')
  elseif (button == 144) then lmc_send_keys('^+{F17}')
  elseif (button == 111) then lmc_send_input(179, 0, 0) -- Press Play/Pause
  elseif (button == 106) then lmc_send_input(176, 0, 0) -- Press Next Track
  elseif (button == 109) then lmc_spawn("spotify")
  else print('Not yet assigned: ' .. button)
  end
end)

-- if you wanted more keyboards, just repeat line 5 with its id and a assign a new name, like MACROS2.
-- then repeat the code that starts in line 9, but change the name to the one you have just assigned.
-- For exemple, to: lmc_set_handler('MACROS2', ...
                                                                                                                    

admin
Site Admin
Posts: 735
Joined: 01 Nov 2010, 13:00
Location: Prague, Czech republic
Contact:

Re: Big Issue, Lua doesn't work when OBS is in the focus

Post by admin » 07 Oct 2020, 08:31

lmc_send_keys just simulated the keypress to it arrives to active application (in focus). How is it suppose to work if your app is not in focus?
Maybe only if it could ready "global hotkeys" (when not in focus) and I'm not sure if that would work with simulated key presses that luamacros triggers...
Petr Medek
LUAmacros author

4Sol
Posts: 3
Joined: 23 Sep 2020, 19:02

Re: Big Issue, Lua doesn't work when OBS is in the focus

Post by 4Sol » 07 Oct 2020, 10:47

foggydude
I'm using ALT+NUM1-9 and CTRL+ALT+F4 (to shut down triggered commands).
Check first with notepad (without OBS)
Like pressing 1-9 on lum-numpad should give you this: ☺☻♥♦♣♠•◘○
F11 should enlarge your browser screen, etc
Some combinations are not working, because they are originally giving you back a beep sound.

For scene switches I'm using main keyboard with CTRL+NUM 1-9

I can give you my code, If you want

Sparc343
Posts: 1
Joined: 31 Oct 2020, 00:23

Re: Big Issue, Lua doesn't work when OBS is in the focus

Post by Sparc343 » 31 Oct 2020, 01:02

As a note to admin: as you can see below, this OBS program they speak of (if configured correctly) is always "scanning for hotkeys" ;) It seems to work well for me personally (brand new user, only been at it a few hours so far)...

To both of you having focus issues, you should First check within OBS. OBS has settings under "advanced" that control "hotkeys" and their behavior. The THREE different settings are:
-Never disable hotkeys
-Disable hotkeys when main window is in focus
-Disable hotkeys when main window is not in focus
That could actually be the singular explanation to Both of your problems, if you have that setting incorrectly set! Your best bet is to set it to NEVER DISABLE HOTKEYS, if that is the functionality you seek!
That being said, I (so far) have had no issues with OBS picking up on my hotkeys either way: while not in focus, or while in focus. I also have my settings set to "never disable hotkeys".

You two may also want to assure that you're using the most up to date version of OBS - which as of this writing is v26.0.2
Furthermore, also make sure you're not running OBS "as admin" - I'm not 100% sure that could be causing the issues you speak of, but I do know I have never ran OBS as admin... I literally just checked to see if I could replicate this problem though two seconds ago: I ran OBS as admin, and despite the settings being set to "never disable hotkeys" it NO longer worked WHILE OBS was IN focus. So indeed, do NOT run as admin. I must add that, while running OBS as admin, it DID still "pick up" the hotkey shortcuts ONLY so long as it was NOT in focus (while ran as admin)... So, that being said - DO NOT run as admin! Note: I am also NOT running LUAM "as admin" either...

[spoiler]not that I personally understand why you want or need the hotkeys to work while it's in focus anyway, since I presumed the whole idea or necessity for hotkeys was so that you could still control it while in other programs/games - especially for those not fortunate enough to have multiple displays... If you're already "IN" the program, why would you need "hotkeys" - since almost everything (while IN focus) is like literally TWO clicks away!
but, to each their own :)[/spoiler]

TL;DR
At any rate: if having issues like described in this thread you will want to assure a few things: First) that all of your settings are correct, Second) that you are NOT running OBS or LUAM "as admin" - or maybe that you're running BOTH "as admin"? Haven't tried that one yet either. But I am almost sure (logically thinking anyway) that if you are only running one OR the other as admin, that you WILL most likely have "issues"...! So I would say either make sure to run both as normal user, or run both as admin!

That being said, LUAM seems SO much better than HIDM - I had a problem with OBS not picking up hotkeys from HIDM while out of focus. Using LUAM, I have had NO issues as of yet :D Now back to the script I am writing for the very same primary purpose (OBS) :D
Attachments
settings.png
settings.png (172.1 KiB) Viewed 5544 times

Post Reply