Sending hotkeys to browser dock


New Member
Hi all,

I'm looking for a method to send keypresses to a browser dock when it's not focused. I have an HTTP interface in a browser dock which I would like to control with keyboard shortcuts even when the dock isn't focused. Ideally this would all be done from a Python script, but it looks like that will need work on the API to make it possible.

Some context: I have written a Python program to control a PowerPoint slideshow with an HTTP/WebSocket interface. The intention is that I can add a browser dock in OBS to show the locally-hosted HTTP interface and control the slideshow from within OBS. This works fine, and in fact I've been using this system for about 6 months. However, the keyboard shortcuts I implemented in the interface only work when the browser dock is focused in OBS, and as soon as I click out of the dock the keyboard shortcuts don't work (see Shortcuts / hotkeys for online web docks).

To get around this, I have been using a separate Python script in OBS which takes in hotkey events and sends commands to the backend directly over WebSocket. This works alright, but I'd like the hotkeys to be able to control over HTTP interface directly, rather than running both the HTTP client and the OBS script in parallel.

The simplest way to fix this seems to be a script which registers hotkeys with OBS as usual, and when a certain key is pressed, it calls a method on the browser dock to send a key, like these snippets for browser sources which use send_hotkey_to_browser(): [1] [2]. However, no such API has been written for browser docks as far as I can tell, and I'm having trouble working out exactly how I would add this to the source.

Another option I thought of is somehow using the CEF devtools (activated by the --remote-debugging-port=... argument) to send input, since this could easily be manipulated with something like selenium. But I can't see any easy way to enable the devtools at runtime.

Any ideas?


New Member
Did you find a solution for this?
No, not yet. Here is the Python script I've been using in case you're interested - This could easily be adapted to send GET requests or something else. However, it looks like the teleprompter you're using is pure JS with no server-side component so that probably won't be much help to you.

I've just had another look at the OBS browser dock implementation and it actually should be pretty easy to add a BrowserDock::SendKeyClick function into browser-panel.cpp. The function for browser sources in obs-browser-source.cpp can probably be copied almost verbatim, since both use the underlying CefBrowser which has a convenient SendKeyEvent method (actually it's the cef host that has this method, but I think that's abstracted away).

When I've got more time I'll try and implement that function and the corresponding API in libobs, and hopefully make a pull request. The next step might be to add a feature which redirects keypresses from the interface to browser docks, although I'm not quite sure how the logic of that would work. At least once there's a function and API for it we can use a Python/Lua script to take in hotkeys from OBS and send them to the browser dock.


New Member
I just had a look... that is some of the most hacky and inefficient code I have ever seen. It's literally writing to disk every time you press a hotkey, and the file is reloaded by the main JS every 200 ms. At least load the file as a text file and parse it yourself rather than interpreting a whole JS file 5 times a second!

Feel free to have a go, but personally I wouldn't even try. It's impossible to make this approach ever work efficiently and reliably.


Hey @alorimer did you ever find a solution to this?
My use case is I'm using Companion to turn on and off Restream channels. I have a Restream browser dock in OBS. However the Restream toggles aren't ajax so you have to reload the browser dock if you want to see any changes. I was hoping for a hotkey to initiate a reload of the browser dock.
The best I can think of for now is to use some program to automatically move my mouse over the browser dock and press Ctrl+R.