2017-09-25 6 views
1

Windowsシステムでは、Python/QT GUIを実行しています。今すぐボタンを押して私は最小化された、または私のアプリケーションの前に最小化されていないGoogleのクロムをアクティブにする必要があります。Google chrome - Google Chromeを有効にして特定のタブウィンドウに切り替える方法

Google chromeを有効にして、static title nameまたはprocess id titles(Pythonなどを使用)で特定のTABに切り替えるにはどうすればよいですか?

(例えば2番目のタブをアクティブ) enter image description here

の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 
+1

ウェブブラウザーは、自動ホットのような製品に相当するものではありません。 Pythonを使用してマウスを制御し、キーストロークを送信する場合は、PyWinAutoなどの製品を探します。 –

答えて

0

作品。

chrome := "- Google Chrome" 
found := "false" 
tabSearch := "Gmail" 
curWinNum := 0 
SetTitleMatchMode, 2 
WinGet, numOfChrome, Count, %chrome% ; Get the number of chrome windows 
WinActivateBottom, %chrome% ; Activate the least recent window 
WinWaitActive %chrome% ; Wait until the window is active 
ControlFocus, Chrome_RenderWidgetHostHWND1 ; Set the focus to tab control ??? 
while (curWinNum < numOfChrome and found = "false") { 
    WinGetTitle, firstTabTitle, A ; The initial tab title 
    title := firstTabTitle 
    Loop { 
     if(InStr(title, tabSearch)>0){ 
      found := "true" 
      break 
     } 
     Send {Ctrl down}{Tab}{Ctrl up} 
     Sleep, 50 
     WinGetTitle, title, A ;get active window title 
     if(title = firstTabTitle){ 
      break 
     } 
    } 
    WinActivateBottom, %chrome% 
    curWinNum := curWinNum + 1 
} 

if(found = "false"){ 
    Run "https://gmail.com" 
}  
return 
+0

最初の "break"を "return"に変更します。アクティブなウィンドウがさらにある場合は、ループが終了した後にWinActivateBottomが呼び出され、タブがすでに検出されていても次のウィンドウがアクティブになります。 –

関連する問題