"Capture foreground window with hotkey" function for Window Capture

Gambloide

New Member
Use Case
To reduce the need to rely on a Screen Capture source for streams, I would love to be able to change the input for a Window Capture source with a hotkey, the same way we can do it for Game Capture sources.

Details
Relying on Screen Capture is a needless security risk during live streams, which tends to have people accidentally leak private or sensitive information.

But given the frequency with which streamers tend to switch between applications or windows when they e.g. stream working on something, it is not reasonable to always go into OBS, navigate to a window capture source in question, open its settings, then change the window based on its title in a potentially really long dropdown list, apply the settings and get back to where they were. This just makes the idea of using Window Capture sources for stream like that a non-starter.

The option to just define a hotkey to switch a given Window Capture source to the active Window would solve this quite elegantly.

Prior Work
- This feature is already implemented for Game Capture sources in https://github.com/obsproject/obs-studio/blob/master/plugins/win-capture/game-capture.c
- Someone wrote a Lua script attempting to achieve this functionality, but this script has multiple bugs: https://demonastery.org/2020/05/window-capture-hotkey-obs/
- I adjusted the aforementioned script as follows:
-- I made it so the Window Capture source can be in any scene, not just the active one
-- I made the script also detect the executable, so the source can be set to "Match Window title, otherwise find window of same executable"
However, since OBS depends on LuaJIT for its Lua scripting support and LuaJIT doesn't support modern Lua features, it is not possible to extract the title of any window title with non-ASCII characters, which makes it impossible to set the title with https://docs.obsproject.com/reference-settings#c.obs_data_set_string. This is a show-stopper as well, since e.g. any Firefox window title contains an Em Dash (—), which LuaJIT and the OBS Lua bindings can't handle. (If someone can show me how I am wrong on this part and how you could still achieve this in a Lua script in OBS you are more than welcome. I would love to be proven wrong).

Non-Solutions
- The automatic scene switcher cannot be used to achieve a similar function. Primarily because window titles have to be know beforehand for this approach, which is not possible. Even if that was not a restriction, it would still be almost exactly as bad as a Display Capture, since it would just automatically switch when you e.g. alt-tab to a window, even if that is e.g. a login or payment form in a browser.
 

AaronD

Active Member
Relying on Screen Capture is a needless security risk during live streams, which tends to have people accidentally leak private or sensitive information.
Don't have sensitive stuff up. Problem solved. Streaming and privacy are inherently not compatible, so don't make it a problem.

change the window based on its title in a potentially really long dropdown list,
You're doing too much at the same time. Pare it down. Close *everything* that is not *specifically* needed for *that* stream, so it doesn't appear in that list.

And we have lots of complaints about the Game Capture and Application Capture not working. Nice idea, but still full of bugs. I tell people to use the old Window- and Screen Captures instead, 'cause they work.

- I adjusted the aforementioned script as follows:
-- I made it so the Window Capture source can be in any scene, not just the active one
-- I made the script also detect the executable, so the source can be set to "Match Window title, otherwise find window of same executable"
However, since OBS depends on LuaJIT for its Lua scripting support and LuaJIT doesn't support modern Lua features, it is not possible to extract the title of any window title with non-ASCII characters, which makes it impossible to set the title with https://docs.obsproject.com/reference-settings#c.obs_data_set_string. This is a show-stopper as well, since e.g. any Firefox window title contains an Em Dash (—), which LuaJIT and the OBS Lua bindings can't handle. (If someone can show me how I am wrong on this part and how you could still achieve this in a Lua script in OBS you are more than welcome. I would love to be proven wrong).
Good start. Maybe someone has an answer for that, but still see above.

when you e.g. alt-tab to a window, even if that is e.g. a login or payment form in a browser.
Like I said above, don't have that open! Keep your rig clean, and ONLY have stuff running that you're EXPLICITLY going to use for THIS EXACT stream. Then you don't have a problem.

In fact, keep your machine clean anyway. What's the difference between 100 open tabs and a set of 100 bookmarks, except that you *know* that a closed tab won't be shown? And a slight performance hit because each one you have open takes some resources. Likewise for windows, and the shortcuts to open them.

Spend one extra second when you're done with each thing, to close it. Completely. Just reach up and hit the X.
 
Top