Jump to content

Pause YouTube video via ControlSend


Recommended Posts

As the title suggests I am looking for a way to pause YouTube videos using ControlSend as the video is an inactive window.

I am only aware that pausing a video can be done so by hitting the "Space" key WITHIN the video. I assumed I could achieve this by using the following code:

ControlSend("[CLASS:Chrome_WidgetWin_1]", "", "[CLASS:Chrome_RenderWidgetHostHWND]", "{SPACE}")

This is not doing anything though. I have also tried ControlClick but with no success.

Is there something outside the box I am not thinking of? If all else fails I will just activate the window and click at a coordinate.

Snapshot of window information:

example.jpg

Edited by kjpolker
Link to post
Share on other sites

Provided you where getting the correct $hWnd and the last click was in the video frame then this should work for you without any problems, maybe its possible to pin in to the video frame control with the chrome UDF  not sure, didn't look into it
Otherwise this might be the easiest - simple solution yet .. 

  

#include <WinAPI.au3>

$hWnd = WinGetHandle("[CLASS:Chrome_WidgetWin_1]")
If Not @error Then _PlayPause(_WinAPI_GetWindow($hWnd, $GW_HWNDNEXT))

Func _PlayPause($hWnd)
    If Not StringInStr(WinGetTitle($hWnd, ""), "YouTube") Then Return
    Local $hC = "Chrome_RenderWidgetHostHWND1"
    ControlFocus($hWnd, "", $hC)
    ControlSend($hWnd, "", $hC, "{SPACE}")
EndFunc

 

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...