0

我希望能够从 Autohotkey 触发“搜索选项卡”,因为我有很多打开的选项卡,这将帮助我快速找到我正在寻找的选项卡,我知道我可以通过编写脚本来遍历所有选项卡,但这不是我想要的。

这就是我所做的

!+a::
  WinActivate, Brave
  Sleep, 100
  Send, {Ctrl}{Shift}a
Return

如果我更改Send, {Ctrl}{Shift}aSend, {Ctrl}t正确打开一个选项卡,那么问题一定是我的{Ctrl}{Shift}a配置中的一些错误,或者 Brave 以某种方式没有反应。

4

1 回答 1

1

激活特定窗口并向其发送击键的最合适方法如下:

!+a::
    SetTitleMatchMode, 2 ; if you want to use it only in this hotkey
    IfWinNotExist, Brave
    {
        MsgBox, Cannot find Brave
            Return ; end of the hotkey's code
    }
    ; otherwise:
    WinActivate, Brave
    WinWaitActive, Brave, ,2  ; wait 2 seconds maximally  until the specified window is active
    If (ErrorLevel)  ;  if the command timed out
    {
        MsgBox, Cannot activate Brave
            Return
    }
    ; otherwise:
    ; Sleep 300 ; needed in some programs that may not react immediately after activated
    Send, ^+a
Return

否则脚本可以将击键发送到另一个窗口。

为了不在每个热键中重复整个代码,您可以创建一个函数:

!+b::
    SetTitleMatchMode, 2
    Activate("Brave", 2)
    ; Sleep 300
    Send, ^+a
Return

Activate(title, seconds_to_wait){
    IfWinNotExist, % title
    {
        MsgBox % "Cannot find """ . title . """."
            Return
    }
    ; otherwise:
    WinActivate, % title
    WinWaitActive, % title, ,% seconds_to_wait
    If (ErrorLevel) 
    {
        MsgBox % "Cannot activate """ . title . """."
            Return
    }
}
于 2021-10-08T10:12:17.840 回答