pattymills
pattymills

Reputation: 137

Autohotkey Simple ControlSend to Google Chrome

EDIT for working version

!j::
SetTitleMatchMode, 2

ControlGet, OutputVar, Hwnd,,Chrome_RenderWidgetHostHWND1, Google Chrome

ControlFocus,,ahk_id %outputvar%


ControlSend, , {Space} , Google Chrome

Original post:

DetectHiddenWindows, on
!j::
IfWinExist, ahk_exe chrome.exe
ControlSend, ahk_exe chrome.exe, {SPACE}
return

What I want is to be able to toggle Play/Pause on a youtube video that is playing through chrome. The chrome window is not the active window, but is showing on my second monitor. I've tried using the ahk_class Chrome_WidgetWin_1 from WindowSpy and also doing a ControlClick with the ClassNN: Chrome_RenderWidgetHostHWND1 but nothing seems to properly send a {SPACE} or CLICK to pause the video.

WindowSpy info (the video title will not be consistent):

Calculus 2 Lecture 10.2: Introduction to Parametric Equations - YouTube - Google Chrome
ahk_class Chrome_WidgetWin_1
ahk_exe chrome.exe

Absolute:   -908, 634 (less often used)
Relative:   1012, 634 (default)
Client: 1012, 634 (recommended)

ClassNN:    Intermediate D3D Window1
Text:   
Color:  05070D (Red=05 Green=07 Blue=0D)
    x: 0    y: 0    w: 1920 h: 1080
Client: x: 0    y: 0    w: 1920 h: 1080

Chrome Legacy Window
Chrome Legacy Window

Chrome Legacy Window
Chrome Legacy Window

Upvotes: 0

Views: 5359

Answers (1)

Bob
Bob

Reputation: 431

Do consult with documentation first: https://autohotkey.com/docs/commands/ControlSend.htm

ControlSend, Control, Keys, WinTitle

while you have

ControlSend, ahk_exe chrome.exe, {SPACE}

ahk_exe chrome.exe is considered as valid WinTitle parameter, NOT as valid Control.

Therefore, what you want is:

ControlSend,,{SPACE},ahk_exe chrome.exe

Additionally, as you can read in ControlSend documentation:

If this (Control) parameter is blank or omitted, the target window's topmost control will be used. If this parameter is ahk_parent, the keystrokes will be sent directly to the target window instead of one of its controls

So if above line of code does not work for you, you might want to use:

ControlSend,ahk_parent,{SPACE},ahk_exe chrome.exe

Upvotes: 1

Related Questions