1
在Windows系統上,我運行了Python/QT GUI。現在按下按鈕,我需要在我的應用程序前激活最小化或不最小化的Google Chrome。谷歌瀏覽器 - 如何激活谷歌瀏覽器並切換到特定的選項卡窗口?
如何激活谷歌瀏覽器,然後切換到一個非常具體的選項卡static title name
或process id titles
(使用Python或其他方式)?
的Python:(不起作用它只是努力打開它)
import webbrowser
url = 'http://docs.python.org/'
chrome_path = 'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe %s'
webbrowser.get(chrome_path).open(url)
AHK:失敗
#d::
list := Acc_Get("Object", "4.23.1", 0, "ahk_class MozillaWindowClass")
;MsgBox % list.accChildCount-1
for each, tab in Acc_Children(list) {
MsgBox, % tab.accName(0)
tab.accDoDefaultAction(0)
}
Return
#c::WinActivate("Calculator", "calc")
#NoTrayIcon
#SingleInstance force
WinActivate(TheWindowTitle, TheProgramTitle)
{
SetTitleMatchMode,2
DetectHiddenWindows, Off
IfWinExist, %TheWindowTitle%
{
WinGet, winid, ID, %TheWindowTitle%
DllCall("SwitchToThisWindow", "UInt", winid, "UInt", 1)
}
Else
{
Run %TheProgramTitle%
}
Return
}
試一試:
If ChromeHasTabNamed("Activating Chrome Tab")
MsgBox, Yes
Return
ChromeHasTabNamed(X) {
SetTitleMatchMode, 2
WinGetTitle, title, - Chrome
While Not InStr(list, title "`n") {
list .= title "`n"
ControlSend,, ^{Tab}, - Chrome
Sleep, 50
WinGetTitle, title, - Chrome
}
Return, InStr(list, X) ? True : False
}
TRY直到死去:
SetTitleMatchMode, 2
WinWaitActive - Google Chrome
ControlFocus, Chrome_RenderWidgetHostHWND1
Loop, 15
{
WinGetTitle, Title, A ;get active window title
if(InStr(Title, "Gmail")>0)
{
break ; Terminate the loop
}
Send ^{Tab}
Sleep, 50
}
return
webbrowser並不打算作爲像autohotkey這樣的產品的等價物。如果您想使用Python來控制鼠標併發送按鍵,請查找PyWinAuto等產品。 –