@@ -345,3 +345,73 @@ RpcResponse WSRequestHandler::OpenProjector(const RpcRequest& request) {
345
345
obs_frontend_open_projector (type, monitor, geometry, name);
346
346
return request.success ();
347
347
}
348
+
349
+ /* *
350
+ * Executes hotkey routine, identified by hotkey unique name
351
+ *
352
+ * @param {String} `hotkeyName` Unique name of the hotkey, as defined when registering the hotkey (e.g. "ReplayBuffer.Save")
353
+ *
354
+ * @api requests
355
+ * @name TriggerHotkeyByName
356
+ * @category general
357
+ * @since unreleased
358
+ */
359
+ RpcResponse WSRequestHandler::TriggerHotkeyByName (const RpcRequest& request) {
360
+ const char * name = obs_data_get_string (request.parameters (), " hotkeyName" );
361
+
362
+ obs_hotkey_t * hk = Utils::FindHotkeyByName (name);
363
+ if (!hk) {
364
+ return request.failed (" hotkey not found" );
365
+ }
366
+ obs_hotkey_trigger_routed_callback (obs_hotkey_get_id (hk), true );
367
+ return request.success ();
368
+ }
369
+
370
+ /* *
371
+ * Executes hotkey routine, identified by bound combination of keys. A single key combination might trigger multiple hotkey routines depending on user settings
372
+ *
373
+ * @param {String} `keyId` Main key identifier (e.g. `OBS_KEY_A` for key "A"). Available identifiers [here](https://github.com/obsproject/obs-studio/blob/master/libobs/obs-hotkeys.h)
374
+ * @param {Object (Optional)} `keyModifiers` Optional key modifiers object. False entries can be ommitted
375
+ * @param {boolean} `keyModifiers.shift` Trigger Shift Key
376
+ * @param {boolean} `keyModifiers.alt` Trigger Alt Key
377
+ * @param {boolean} `keyModifiers.control` Trigger Control (Ctrl) Key
378
+ * @param {boolean} `keyModifiers.command` Trigger Command Key (Mac)
379
+ *
380
+ * @api requests
381
+ * @name TriggerHotkeyByCombination
382
+ * @category general
383
+ * @since unreleased
384
+ */
385
+ RpcResponse WSRequestHandler::TriggerHotkeyBySequence (const RpcRequest& request) {
386
+ if (!request.hasField (" keyId" )) {
387
+ return request.failed (" missing request keyId parameter" );
388
+ }
389
+
390
+ OBSDataAutoRelease data = obs_data_get_obj (request.parameters (), " keyModifiers" );
391
+
392
+ obs_key_combination_t combo = {0 };
393
+ uint32_t modifiers = 0 ;
394
+ if (obs_data_get_bool (data, " shift" ))
395
+ modifiers |= INTERACT_SHIFT_KEY;
396
+ if (obs_data_get_bool (data, " control" ))
397
+ modifiers |= INTERACT_CONTROL_KEY;
398
+ if (obs_data_get_bool (data, " alt" ))
399
+ modifiers |= INTERACT_ALT_KEY;
400
+ if (obs_data_get_bool (data, " command" ))
401
+ modifiers |= INTERACT_COMMAND_KEY;
402
+
403
+ combo.modifiers = modifiers;
404
+ combo.key = obs_key_from_name (obs_data_get_string (request.parameters (), " keyId" ));
405
+
406
+ if (!modifiers
407
+ && (combo.key == OBS_KEY_NONE || combo.key >= OBS_KEY_LAST_VALUE)) {
408
+ return request.failed (" invalid key-modifier combination" );
409
+ }
410
+
411
+ // Inject hotkey press-release sequence
412
+ obs_hotkey_inject_event (combo, false );
413
+ obs_hotkey_inject_event (combo, true );
414
+ obs_hotkey_inject_event (combo, false );
415
+
416
+ return request.success ();
417
+ }
0 commit comments