Skip to content

Commit

Permalink
➕ Add hold feature, write description in scripts menu
Browse files Browse the repository at this point in the history
  • Loading branch information
upgradeQ committed Dec 23, 2020
1 parent 66d85ab commit 4fff6eb
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Select source with filters, add Filter hotkey filter to it.

In settings bind hotkeys for each filter.

Note: 0 - means disable filter , 1 - enable , 2 - toggle
Note: 0 - means disable filter , 1 - enable , 2 - toggle , 3 - hold

# Current limitations
Hotkeys deregistered only after restart
Expand Down
27 changes: 25 additions & 2 deletions filter_hotkeys_audio.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
local obs = obslua
local bit = require("bit")

function script_description()
return [[Select source with filters, add "Filter hotkeys video/audio" to it. <br>
In settings bind hotkeys for each filter. <br>
Note: 0 - means disable filter , 1 - enable , 2 - toggle, 3 - hold ]]
end

local info = {} -- obs_source_info https://obsproject.com/docs/reference-sources.html
info.id = "_filter_hotkeys_audio"
info.type = obs.OBS_SOURCE_TYPE_FILTER
Expand Down Expand Up @@ -47,6 +53,14 @@ info.reg_htk = function(filter,settings) -- register hotkeys after 100 ms since
obs.obs_source_set_enabled(v,switch)
end

filter.hotkeys["3;" .. source_name .. ";" .. filter_name] = function(pressed)
if pressed then
obs.obs_source_set_enabled(v,true)
else
obs.obs_source_set_enabled(v,false)
end
end

end
end
obs.source_list_release(result)
Expand All @@ -57,8 +71,17 @@ info.reg_htk = function(filter,settings) -- register hotkeys after 100 ms since
end

for k, v in pairs(filter.hotkeys) do
filter.hk[k] = obs.obs_hotkey_register_frontend(k, k, function(pressed)
if pressed then filter.hotkeys[k]() end end)
if k:sub(1,1) == "3" then -- for hold hotkeys which start with 3 symbol
filter.hk[k] = obs.obs_hotkey_register_frontend(k, k, function(pressed)
if pressed then filter.hotkeys[k](true)
else
filter.hotkeys[k](false)
end
end)
else
filter.hk[k] = obs.obs_hotkey_register_frontend(k, k, function(pressed)
if pressed then filter.hotkeys[k]() end end)
end
local a = obs.obs_data_get_array(settings, k)
obs.obs_hotkey_load(filter.hk[k], a)
obs.obs_data_array_release(a)
Expand Down
27 changes: 25 additions & 2 deletions filter_hotkeys_video.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
local obs = obslua
local bit = require("bit")

function script_description()
return [[Select source with filters, add "Filter hotkeys video/audio" to it. <br>
In settings bind hotkeys for each filter. <br>
Note: 0 - means disable filter , 1 - enable , 2 - toggle, 3 - hold ]]
end

local info = {} -- obs_source_info https://obsproject.com/docs/reference-sources.html
info.id = "_filter_hotkeys_video"
info.type = obs.OBS_SOURCE_TYPE_FILTER
Expand Down Expand Up @@ -47,6 +53,14 @@ info.reg_htk = function(filter,settings) -- register hotkeys after 100 ms since
obs.obs_source_set_enabled(v,switch)
end

filter.hotkeys["3;" .. source_name .. ";" .. filter_name] = function(pressed)
if pressed then
obs.obs_source_set_enabled(v,true)
else
obs.obs_source_set_enabled(v,false)
end
end

end
end
obs.source_list_release(result)
Expand All @@ -57,8 +71,17 @@ info.reg_htk = function(filter,settings) -- register hotkeys after 100 ms since
end

for k, v in pairs(filter.hotkeys) do
filter.hk[k] = obs.obs_hotkey_register_frontend(k, k, function(pressed)
if pressed then filter.hotkeys[k]() end end)
if k:sub(1,1) == "3" then -- for hold hotkeys which start with 3 symbol
filter.hk[k] = obs.obs_hotkey_register_frontend(k, k, function(pressed)
if pressed then filter.hotkeys[k](true)
else
filter.hotkeys[k](false)
end
end)
else
filter.hk[k] = obs.obs_hotkey_register_frontend(k, k, function(pressed)
if pressed then filter.hotkeys[k]() end end)
end
local a = obs.obs_data_get_array(settings, k)
obs.obs_hotkey_load(filter.hk[k], a)
obs.obs_data_array_release(a)
Expand Down

0 comments on commit 4fff6eb

Please sign in to comment.