2016-11-30 694 views
0

編輯工作版本AutoHotkey的簡單ControlSend谷歌瀏覽器

!j:: 
SetTitleMatchMode, 2 

ControlGet, OutputVar, Hwnd,,Chrome_RenderWidgetHostHWND1, Google Chrome 

ControlFocus,,ahk_id %outputvar% 


ControlSend, , {Space} , Google Chrome 

原帖:

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

我要的是能夠切換播放/暫停YouTube影片是通過鍍鉻玩。鉻窗口不是活動窗口,但顯示在我的第二臺顯示器上。我嘗試過使用WindowSpy中的ahk_class Chrome_WidgetWin_1,並使用ClassNN:Chrome_RenderWidgetHostHWND1做一個ControlClick,但似乎沒有正確發送{SPACE}或CLICK來暫停視頻。

WindowSpy信息(視頻標題不會是一致的):https://autohotkey.com/docs/commands/ControlSend.htm

ControlSend, Control, Keys, WinTitle 

,而你有

ControlSend, ahk_exe chrome.exe, {SPACE} 

ahk_exe chrome.exe認爲:

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 

回答

1

與文檔先別諮詢如valid WinTitle參數,NOT as valid Control

因此,你要的是:

ControlSend,,{SPACE},ahk_exe chrome.exe 

此外,你可以在ControlSend文檔閱讀:

如果這(Control)參數爲空或省略,目標窗口將使用最上面的 控件。如果這個參數是ahk_parent,擊鍵 將被直接發送到目標窗口,而不是它的 控件之一

所以,如果上面的代碼行不爲你工作,你可能想使用:

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