Hello, I am trying to make a lua script which allows me to use a hotkey and change the target window of the window source.
Example I have window capture and I selected notepad. It will capture and show notepad window. Now on desktop I change focus chrome. If I press the hotkey so the source should change to the current window as target window. In this case it should show chrome now instead of notepad.
OnHotkeyChangeState will get called if I use the hotkey. But after the line with "if windowProp ~= nil then" I am not what can I do. I only find out that the obs_property_list_item_name id 0 will have always the current focused window. So I am missing something like "select and apply this". I found only apply but it is not working or maybe I did something wrong there.
Example I have window capture and I selected notepad. It will capture and show notepad window. Now on desktop I change focus chrome. If I press the hotkey so the source should change to the current window as target window. In this case it should show chrome now instead of notepad.
Code:
function OnHotkeyChangeState(pressed)
if not pressed then
return false
end
if not hasSource then
return false
end
local source = obs.obs_get_source_by_name(select_window_source)
if source ~= nil then
if obs.obs_source_get_id(source) == "window_capture" then
local properties = obs.obs_source_properties(source)
local windowProp = obs.obs_properties_get(properties, "window")
if windowProp ~= nil then
print(obs.obs_property_list_item_name(windowProp, 0))
local settings = obs.obs_source_get_settings(source)
obs.obs_properties_apply_settings(properties, settings)
end
end
end
obs.obs_source_release(source)
end
OnHotkeyChangeState will get called if I use the hotkey. But after the line with "if windowProp ~= nil then" I am not what can I do. I only find out that the obs_property_list_item_name id 0 will have always the current focused window. So I am missing something like "select and apply this". I found only apply but it is not working or maybe I did something wrong there.