【发布时间】:2018-03-06 11:59:38
【问题描述】:
在 Windows 系统上,我正在运行 Python/QT GUI。现在按下按钮,我需要在我的应用程序前面激活最小化或未最小化的谷歌浏览器。
如何激活谷歌浏览器,然后通过static title name或process id titles(使用Python或其他方式)切换到非常具体的TAB?
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
}
尝试直到死亡:
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 等产品。
标签: python windows google-chrome autohotkey hotkeys