local obs = obslua
-- Full list of the available hotkeys (OBS v29.1.2)
-- https://github.com/obsproject/obs-studio/blob/cb391a595d45aea0d710680c143eb90efe22998b/libobs/obs-hotkeys.h
-- Recording paused hotkey
rec_paused_key = "OBS_KEY_NUM9"
rec_paused_key_modifires = {control=true} ---- {shift=true, alt=true, control=true, command=true}
-- Recording unpaused hotkey
rec_unpaused_key = "OBS_KEY_NUM8"
rec_unpaused_key_modifires = {control=true} ---- {shift=true, alt=true, control=true, command=true}
-- Recording started hotkey
rec_started_key = "OBS_KEY_NUM7"
rec_started_key_modifires = {control=true} ---- {shift=true, alt=true, control=true, command=true}
-- Recording stopped hotkey
rec_stopped_key = "OBS_KEY_NUM6"
rec_stopped_key_modifires = {control=true} ---- {shift=true, alt=true, control=true, command=true}
----------------------------------------------------------
-- This function triggers OBS hotkey event
function send_hotkey(hotkey_id_name, key_modifiers)
local shift_mod = key_modifiers.shift or false
local control_mod = key_modifiers.control or false
local alt_mod = key_modifiers.alt or false
local command_mod = key_modifiers.command or false
local modifiers = 0
if shift_mod then
modifiers = bit.bor(modifiers, obs.INTERACT_SHIFT_KEY )
end
if control_mod then
modifiers = bit.bor(modifiers, obs.INTERACT_CONTROL_KEY )
end
if alt_mod then
modifiers = bit.bor(modifiers, obs.INTERACT_ALT_KEY )
end
if command_mod then
modifiers = bit.bor(modifiers, obs.INTERACT_COMMAND_KEY )
end
local combo = obs.obs_key_combination()
combo.modifiers = modifiers
combo.key = obs.obs_key_from_name(hotkey_id_name)
obs.obs_hotkey_inject_event(combo, false)
obs.obs_hotkey_inject_event(combo, true)
obs.obs_hotkey_inject_event(combo, false)
end
----------------------------------------------------------
-- A function named script_description returns the description shown to
-- the user
function script_description()
local ctrl_paused = rec_paused_key_modifires.control or false
local alt_paused = rec_paused_key_modifires.alt or false
local shift_paused = rec_paused_key_modifires.shift or false
local command_paused = rec_paused_key_modifires.command or false
local ctrl_unpaused = rec_unpaused_key_modifires.control or false
local alt_unpaused = rec_unpaused_key_modifires.alt or false
local shift_unpaused = rec_unpaused_key_modifires.shift or false
local command_unpaused = rec_unpaused_key_modifires.command or false
local ctrl_started = rec_started_key_modifires.control or false
local alt_started = rec_started_key_modifires.alt or false
local shift_started = rec_started_key_modifires.shift or false
local command_started = rec_started_key_modifires.command or false
local ctrl_stopped = rec_stopped_key_modifires.control or false
local alt_stopped = rec_stopped_key_modifires.alt or false
local shift_stopped = rec_stopped_key_modifires.shift or false
local command_stopped = rec_stopped_key_modifires.command or false
local modifiers_paused = ""
local modifiers_unpaused = ""
local modifiers_started = ""
local modifiers_stopped = ""
if ctrl_paused then
modifiers_paused = modifiers_paused .. "CTRL + "
end
if alt_paused then
modifiers_paused = modifiers_paused .. "ALT + "
end
if shift_paused then
modifiers_paused = modifiers_paused .. "SHIFT + "
end
if command_paused then
modifiers_paused = modifiers_paused .. "COMMAND + "
end
if ctrl_unpaused then
modifiers_unpaused = modifiers_unpaused .. "CTRL + "
end
if alt_unpaused then
modifiers_unpaused = modifiers_unpaused .. "ALT + "
end
if shift_unpaused then
modifiers_unpaused = modifiers_unpaused .. "SHIFT + "
end
if command_unpaused then
modifiers_unpaused = modifiers_unpaused .. "COMMAND + "
end
if ctrl_started then
modifiers_started = modifiers_started .. "CTRL + "
end
if alt_started then
modifiers_started = modifiers_started .. "ALT + "
end
if shift_started then
modifiers_started = modifiers_started .. "SHIFT + "
end
if command_started then
modifiers_started = modifiers_started .. "COMMAND + "
end
if ctrl_stopped then
modifiers_stopped = modifiers_stopped .. "CTRL + "
end
if alt_stopped then
modifiers_stopped = modifiers_stopped .. "ALT + "
end
if shift_stopped then
modifiers_stopped = modifiers_stopped .. "SHIFT + "
end
if command_stopped then
modifiers_stopped = modifiers_stopped .. "COMMAND + "
end
return "Fires hotkeys for internals of OBS:\n" ..
modifiers_paused .. rec_paused_key .. " on 'Recording paused'\n" ..
modifiers_unpaused .. rec_unpaused_key .. " on 'Recording unpaused'\n" ..
modifiers_started .. rec_started_key .. " on 'Recording started'\n" ..
modifiers_stopped .. rec_stopped_key .. " on 'Recording stopped'"
end
-- OBS events and corresponding actions
function on_event(event)
if event == obs.OBS_FRONTEND_EVENT_RECORDING_PAUSED then
send_hotkey(rec_paused_key, rec_paused_key_modifires)
elseif event == obs.OBS_FRONTEND_EVENT_RECORDING_UNPAUSED then
send_hotkey(rec_unpaused_key, rec_unpaused_key_modifires)
elseif event == obs.OBS_FRONTEND_EVENT_RECORDING_STARTED then
send_hotkey(rec_started_key, rec_started_key_modifires)
elseif event == obs.OBS_FRONTEND_EVENT_RECORDING_STOPPED then
send_hotkey(rec_stopped_key, rec_stopped_key_modifires)
end
end
-- A function named script_load will be called on startup
function script_load(settings)
obs.obs_frontend_add_event_callback(on_event)
end