bradleyp
New Member
I'm trying to write a script to automatically update the Window Capture window when a user changes the current foreground window in Windows. This would eliminate the need to constantly change the currently selected window for recording or for replay buffer. I'm able to use
Here is my script:
I'm looking for some direction, or if I'm on the right track, or if this is possible at all.
Thanks!
obs_data_set_string
, but when I capture using replay buffer, the screen is black as if it's not actually updating.Here is my script:
Python:
import obspython as obs
import time
import win32gui
import win32process
import psutil
source_name = "Window Capture"
def create_title(pid, window):
return f'[{pid}]: {window}'
def get_active_window():
fgWindow = win32gui.GetForegroundWindow()
fgWindowName = win32gui.GetWindowText(fgWindow)
pid = win32process.GetWindowThreadProcessId(fgWindow)
process = psutil.Process(pid[-1]).name()
title = create_title(process, fgWindowName)
return title
def change_window_capture_source(window_title):
source = obs.obs_get_source_by_name(source_name)
settings = obs.obs_data_create()
obs.obs_data_set_string(settings, "window", window_title)
obs.obs_source_update(source, settings)
temp = obs.obs_source_get_settings(source)
print(obs.obs_data_get_json(temp))
# cleanup
obs.obs_data_release(settings)
obs.obs_source_release(source)
def main():
active_window = get_active_window()
change_window_capture_source(active_window)
def script_description():
return "Python script to update Window Capture based on active window"
obs.timer_add(main, 1000)
I'm looking for some direction, or if I'm on the right track, or if this is possible at all.
Thanks!