obs = obslua
source_name = ""
hotkey_id = obs.OBS_INVALID_HOTKEY_ID
interaction_flag = obs.OBS_SOURCE_INTERACTION
bit = require("bit")
----------------------------------------------------------
-- The "Interact window" hotkey callback
function interact_window(pressed)
if not pressed then
return
end
local source = obs.obs_get_source_by_name(source_name)
if source ~= nil then
obs.obs_frontend_open_source_interaction(source)
obs.obs_source_release(source)
end
end
----------------------------------------------------------
-- A function named script_update will be called when settings are changed
function script_update(settings)
source_name = obs.obs_data_get_string(settings, "source")
end
-- A function named script_description returns the description shown to the user
function script_description()
return "When the \"Interact window\" hotkey is triggered, opens Interact window for selected source."
end
-- A function named script_properties defines the properties that the user
-- can change for the entire script module itself
function script_properties()
props = obs.obs_properties_create()
local p = obs.obs_properties_add_list(props, "source", "Interactive Source", obs.OBS_COMBO_TYPE_EDITABLE, obs.OBS_COMBO_FORMAT_STRING)
local sources = obs.obs_enum_sources()
if sources ~= nil then
for _, source in ipairs(sources) do
-- List only sources that has Capability flag of Interaction
if (bit.band(obs.obs_source_get_output_flags(source), interaction_flag) ~= 0) then
local name = obs.obs_source_get_name(source)
obs.obs_property_list_add_string(p, name, name)
else
-- print(source_id)
end
end
end
obs.source_list_release(sources)
return props
end
-- A function named script_load will be called on startup
function script_load(settings)
-- Here the script_path is used as name to that each copy
-- of the same script (renamed or in a different directory)
-- can has its own hotkey
hotkey_id = obs.obs_hotkey_register_frontend(script_path(), "Interact window", interact_window)
local hotkey_save_array = obs.obs_data_get_array(settings, "interact_window.trigger")
obs.obs_hotkey_load(hotkey_id, hotkey_save_array)
obs.obs_data_array_release(hotkey_save_array)
end
-- A function named script_save will be called when the script is saved
--
-- NOTE: This function is usually used for saving extra data (such as in this
-- case, a hotkey's save data). Settings set via the properties are saved
-- automatically.
function script_save(settings)
local hotkey_save_array = obs.obs_hotkey_save(hotkey_id)
obs.obs_data_set_array(settings, "interact_window.trigger", hotkey_save_array)
obs.obs_data_array_release(hotkey_save_array)
end