Requests: Add ProcessHotkeyByName

Adds a new request called `ProcessHotkeyByName` which calls the routine
associated with a given hotkey. The hotkey is identified by the unique
name set while registering it. Works with both OBS default hotkeys and
hotkeys added by plugins/scripts.
This commit is contained in:
LorenaGdL 2020-09-29 13:38:32 +00:00
parent f61f45fa23
commit bac5b1551b
3 changed files with 25 additions and 0 deletions

View File

@ -43,6 +43,8 @@ const QHash<QString, RpcMethodHandler> WSRequestHandler::messageMap {
{ "BroadcastCustomMessage", &WSRequestHandler::BroadcastCustomMessage },
{ "ProcessHotkeyByName", &WSRequestHandler::ProcessHotkeyByName },
{ "SetCurrentScene", &WSRequestHandler::SetCurrentScene },
{ "GetCurrentScene", &WSRequestHandler::GetCurrentScene },
{ "GetSceneList", &WSRequestHandler::GetSceneList },

View File

@ -61,6 +61,8 @@ class WSRequestHandler {
RpcResponse BroadcastCustomMessage(const RpcRequest&);
RpcResponse ProcessHotkeyByName(const RpcRequest&);
RpcResponse SetCurrentScene(const RpcRequest&);
RpcResponse GetCurrentScene(const RpcRequest&);
RpcResponse GetSceneList(const RpcRequest&);

View File

@ -345,3 +345,24 @@ RpcResponse WSRequestHandler::OpenProjector(const RpcRequest& request) {
obs_frontend_open_projector(type, monitor, geometry, name);
return request.success();
}
/**
* Executes hotkey routine, identified by hotkey unique name
*
* @param {String} `name` Unique name of the hotkey, as defined when registering the hotkey (e.g. "ReplayBuffer.Save")
*
* @api requests
* @name ProcessHotkeyByName
* @category general
* @since unreleased
*/
RpcResponse WSRequestHandler::ProcessHotkeyByName(const RpcRequest& request) {
const char* name = obs_data_get_string(request.parameters(), "name");
obs_hotkey_t* hk = Utils::FindHotkeyByName(name);
if (!hk) {
return request.failed("Hotkey not found");
}
obs_hotkey_trigger_routed_callback(obs_hotkey_get_id(hk), true);
return request.success();
}