循环浏览 chrome 选项卡,直到找到特定的选项卡 - Autohotkey

问题描述 投票:0回答:1

美好的一天! 该脚本应该转到 Chrome 并循环浏览选项卡,直到找到指定的选项卡(在本例中为 YouTube),然后发送命令并返回到我的初始窗口。 问题是它只是切换到 chrome 而不会循环浏览选项卡,甚至有时它会出错。 谢谢:)

settitlematchmode, 2
^f1::
If Not WinExist("ahk_exe chrome.exe")
 {
 Return
 }
WinGetTitle, Title, A
WinActivate, ahk_class Chrome_WidgetWin_1
 Loop{
  Send, ^{Tab}
  Sleep, 50
  WinGetTitle, CurrentWindowTitle, ahk_class Chrome_WidgetWin_1
  If CurrentWindowTitle contains YouTube
   {
   send {Space}
   ;~ Send {Alt down}   ;back to old window
   ;~ Send {tab}
   WinActivate, %Title%
   Sleep 300
   If not WinActive, ahk_exe chrome.exe
    {
    Send {Alt up}
    break
    Return
    }
   break
   Return
   }
  }
Return
windows automation autohotkey
1个回答
0
投票

在 WinActivate 之后使用 WinWaitActive

settitlematchmode, 2

^f1::
If Not WinExist("ahk_exe chrome.exe")
    Return
WinGetTitle, Title, A
WinActivate, ahk_class Chrome_WidgetWin_1
WinWaitActive, ahk_class Chrome_WidgetWin_1
Loop
{
    Send, ^{Tab}
    WinGetTitle, CurrentWindowTitle, ahk_class Chrome_WidgetWin_1
    If CurrentWindowTitle contains YouTube
    {
       send {Space}
       break
    }   
}
WinActivate, %Title%
WinWaitActive, %Title% 
Return
© www.soinside.com 2019 - 2024. All rights reserved.