Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Request] Add proc handlers to source's public API for scripting #140

Closed
partlyhuman opened this issue Nov 16, 2018 · 5 comments
Closed

Comments

@partlyhuman
Copy link

I would like to script a browser source, specifically I would love to call the source's Refresh() method from a Python OBS script. Adding proc handlers for the browser source's public methods (Refresh, SendMouse*, SendKey*) seems like it would be a simple way to accomplish this, if I understand correctly.

@alphasierra59
Copy link

I too have been looking for a way to refresh the browser through the python API.

@upgradeQ
Copy link

upgradeQ commented Feb 15, 2021

For Refresh() functionality you can update source settings like FPS or no-op CSS change and it will "refresh". See this script.
For SendMouse, SendKey it's possible to use built-in obslua/obspython to route hotkey/mouse events into the browser source.
Currently OBS has those functions available:

  • obs_source_send_focus
  • obs_source_send_key_click
  • obs_source_send_mouse_click
  • obs_source_send_mouse_move
  • obs_source_send_mouse_wheel

Here is how to send a hotkey event to a browser source using obs-libre-macros :

function send_hotkey_tbs1(source,hotkey_id_name,key_up,key_modifiers)
  local key = obs.obs_key_from_name(hotkey_id_name)
  local vk = obs.obs_key_to_virtual_key(key)
  local event = obs.obs_key_event()
  event.native_vkey = vk
  event.modifiers = get_modifiers(key_modifiers) -- bit or combination with interact keys
  event.native_modifiers = event.modifiers
  event.native_scancode = vk
  event.text = "" -- it possible to leave it blank, keys are sent
  obs.obs_source_send_key_click(source,event,key_up)
end
send_hotkey_tbs1(t.source,"OBS_KEY_Q",false)
send_hotkey_tbs1(t.source,"OBS_KEY_Q",true)

Link to obs-browser and to Qt keys .
And example for mouse move

function send_mouse_move_tbs(source,x,y,key_modifiers)
  local event = obs.obs_mouse_event()
  event.modifiers = get_modifiers(key_modifiers)
  event.x = x -- top left is [0,0] 
  event.y = y
  obs.obs_source_send_mouse_move(source,event,false) -- do not leave
end

[EDIT] 2021.3.1 - Fix example & add links

@WizardCM
Copy link
Member

Per @upgradeQ's comment, this is possible via standard OBS API functions, so I'm going to close this as it's a feature request that I would consider out of scope (not to mention I'd like to avoid feature requests in the Issues section).

@alphasierra59
Copy link

Per @upgradeQ's comment, this is possible via standard OBS API functions, so I'm going to close this as it's a feature request that I would consider out of scope (not to mention I'd like to avoid feature requests in the Issues section).

Just to make sure I understand how that method works, it requires binding the refresh command to a hotkey, then calling that hotkey with the API?

@engineering222
Copy link

For Refresh() functionality you can update source settings like FPS or no-op CSS change and it will "refresh". See this script. For SendMouse, SendKey it's possible to use built-in obslua/obspython to route hotkey/mouse events into the browser source. Currently OBS has those functions available:

  • obs_source_send_focus
  • obs_source_send_key_click
  • obs_source_send_mouse_click
  • obs_source_send_mouse_move
  • obs_source_send_mouse_wheel

Here is how to send a hotkey event to a browser source using obs-libre-macros :

function send_hotkey_tbs1(source,hotkey_id_name,key_up,key_modifiers)
  local key = obs.obs_key_from_name(hotkey_id_name)
  local vk = obs.obs_key_to_virtual_key(key)
  local event = obs.obs_key_event()
  event.native_vkey = vk
  event.modifiers = get_modifiers(key_modifiers) -- bit or combination with interact keys
  event.native_modifiers = event.modifiers
  event.native_scancode = vk
  event.text = "" -- it possible to leave it blank, keys are sent
  obs.obs_source_send_key_click(source,event,key_up)
end
send_hotkey_tbs1(t.source,"OBS_KEY_Q",false)
send_hotkey_tbs1(t.source,"OBS_KEY_Q",true)

Link to obs-browser and to Qt keys . And example for mouse move

function send_mouse_move_tbs(source,x,y,key_modifiers)
  local event = obs.obs_mouse_event()
  event.modifiers = get_modifiers(key_modifiers)
  event.x = x -- top left is [0,0] 
  event.y = y
  obs.obs_source_send_mouse_move(source,event,false) -- do not leave
end

[EDIT] 2021.3.1 - Fix example & add links

I have no experience with coding and a little bit with streaming with OBS, can you tell me how I can set my web browser source Pomodoro timer to activate with a hotkey?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants