def send_hotkey(obs_htk_id, key_modifiers=None): if key_modifiers: shift = key_modifiers.get("shift") control = key_modifiers.get("control") alt = key_modifiers.get("alt") command = key_modifiers.get("command") else: shift = control = alt = command = 0 modifiers = 0 if shift: modifiers |= S.INTERACT_SHIFT_KEY if control: modifiers |= S.INTERACT_CONTROL_KEY if alt: modifiers |= S.INTERACT_ALT_KEY if command: modifiers |= S.INTERACT_COMMAND_KEY combo = S.obs_key_combination() combo.modifiers = modifiers combo.key = S.obs_key_from_name(obs_htk_id) if not modifiers and ( # S.OBS_KEY_NONE = 0 ? combo.key == 0 or combo.key >= S.OBS_KEY_LAST_VALUE): raise Exception("invalid key-modifier combination") S.obs_hotkey_inject_event(combo, False) S.obs_hotkey_inject_event(combo, True) S.obs_hotkey_inject_event(combo, False)
def send_hotkey_to_browser(source, obs_htk_id, key_modifiers=None, key_up=False): key = obs.obs_key_from_name(obs_htk_id) vk = obs.obs_key_to_virtual_key(key) event = obs.obs_key_event() event.native_vkey = vk event.modifiers = get_modifiers(key_modifiers) event.native_modifiers = event.modifiers # https://doc.qt.io/qt-5/qkeyevent.html event.native_scancode = vk event.text = "" obs.obs_source_send_key_click(source, event, key_up)