Virtual Keyboard Input for Scene Switching

jarodfedele

New Member
Hi there,

I would like to control my OBS scenes via hotkeys that are simulated via virtual keyboard inputs in Python. Right now I'm attempting to use pynput. Everything works normally except the keypresses don't seem to actually communicate to OBS.

For example, whether OBS is in or out of focus, I can manually type Ctrl+Alt+1 and it will switch my scene for me. If I run Ctrl+Alt+1 through pynput, the command actually occurs and the keys are 'pressed' as evident in other applications, but OBS doesn't seem to recognize that happening.

Any ideas, or any alternative key-pressing systems in Python that would enable me to activate hotkeys?
 

koala

Active Member
In case you're running OBS as admin, you need to run any hotkey generating app as admin as well. Otherwise Windows is blocking keys sent from a non-admin app to an admin app for security reasons.
 

jarodfedele

New Member
In case you're running OBS as admin, you need to run any hotkey generating app as admin as well. Otherwise Windows is blocking keys sent from a non-admin app to an admin app for security reasons.
Thanks for the reply. I am indeed running OBS as admin, so I went ahead and enabled both Reaper and Python to always run as admin (I'm running my DAW Reaper which triggers a Python file to run which triggers the key presses). Still the same issue unfortunately.
 

koala

Active Member
To check if it is really the admin/non-admin issue, run OBS not as admin and check if the generated keys are recognized now. If they are recognized now, you proved your python script isn't running as admin, although you think it is. If they are still not recognized, you have some unknown issue.
 

jarodfedele

New Member
To check if it is really the admin/non-admin issue, run OBS not as admin and check if the generated keys are recognized now. If they are recognized now, you proved your python script isn't running as admin, although you think it is. If they are still not recognized, you have some unknown issue.
Yeah, gave it a shot and the key presses still didn't work. I assume it's some security issue with OBS and/or pynput.
 

jarodfedele

New Member
I should update to say that I tried another similar program, pyKey, with the same issue. So I assume it's not a particular python program and it's moreso Python and/or OBS causing the problem.
 

jarodfedele

New Member
Update - problem SOLVED.

Using AutoHotKey Python wrapper, this is able to be achieved (example using Ctrl+Alt+5):

1598503967491.png
 
Last edited:

brotherbill

New Member
Update - problem SOLVED.

Using AutoHotKey Python wrapper, this is able to be achieved (example using Ctrl+Alt+5):

View attachment 60389
THANK YOU! I've tried pyautogui / keyboard / some other package I can't remember. Was about to give up for the time being until I saw your post. Not sure what AutoHotKey does differently but pleasantly surprised it works when trying to activate hotkeys on streamlabs obs. I made this account just to post this. Thanks again!
 
Top