如何使用AutoHotkey激活Chrome或Firefox中的特定标签?

时间:2017-01-05 05:49:09

标签: google-chrome autohotkey

我有20个不同的标签,我希望只需按Ctrl + A即可打开

以下适用于前9个标签,但不能超出

#SingleInstance, Force
#IfWinActive, ahk_exe chrome.exe
^a::Send, ^2

所以我读过我应该使用WinActivate

我可以让WinActivate使用记事本等程序,但不能使用Chrome标签。有什么想法吗?

^a::
SetTitleMatchMode, 2
IfWinExist, Twitter ahk_class Chrome_WidgetWin_1
  WinActivate

1 个答案:

答案 0 :(得分:2)

我一直致力于实现此功能的功能。我刚刚完成了这个项目, 并且有一个应该实现所需功能的脚本。

注意:根据对Firefox和Chrome的更改,这些脚本可能会中断 在任何时候,就像以前尝试操纵Firefox标签一样, 但请检查AutoHotkey论坛的更新,和/或以下链接:

Firefox / Chrome,获取标签名称/焦点标签 - AutoHotkey社区
https://autohotkey.com/boards/viewtopic.php?f=6&t=26947&p=126248#p126248

注意:此脚本需要运行Acc库,请参阅链接:

Acc库(MSAA)和AccViewer下载链接 - AutoHotkey社区
https://autohotkey.com/boards/viewtopic.php?f=6&t=26201

GroupAdd, vGroupFirefoxAndChrome, ahk_class MozillaWindowClass
GroupAdd, vGroupFirefoxAndChrome, ahk_class Chrome_WidgetWin_1

#IfWinActive, ahk_group vGroupFirefoxAndChrome
^a::
^b::
^c::
^d::
^e::
^f::
^g::
^h::
^i::
^j::
^k::
^l::
^m::
^n::
^o::
^p::
^q::
^r::
^s::
^t::
^u::
^v::
^w::
^x::
^y::
^z::
WinGet, hWnd, ID, A
WinGetClass, vWinClass, ahk_id %hWnd%
vLetter := SubStr(A_ThisHotkey, 1-1)
vNum := Asc(vLetter)-96

if (vWinClass = "MozillaWindowClass")
JEE_FirefoxFocusTabByNum(hWnd, vNum)
if (vWinClass = "Chrome_WidgetWin_1")
JEE_ChromeFocusTabByNum(hWnd, vNum)
Return
#IfWinActive

;==================================================

JEE_FirefoxGetTabNames(hWnd, vSep="`n")
{
oAcc := Acc_Get("Object", "4", 0, "ahk_id " hWnd)
Loop, % oAcc.accChildCount
if (oAcc.accName(A_Index) = "Browser tabs")
if (1, oAcc := Acc_Child(oAcc, A_Index))
break
oAcc := Acc_Child(oAcc, 1)

vOutput := ""
Loop, % oAcc.accChildCount
{
vTabText := oAcc.accName(A_Index)
if !(vTabText == "")
;if !(vTabText == "New Tab")
;if !(vTabText == "Open a new tab")
vOutput .= vTabText vSep
}
vOutput := SubStr(vOutput, 1, -StrLen(vSep)) ;trim right

oAcc := ""
Return vOutput
}

;==================================================

JEE_FirefoxFocusTabByNum(hWnd, vNum)
{
oAcc := Acc_Get("Object", "4", 0, "ahk_id " hWnd)
Loop, % oAcc.accChildCount
if (oAcc.accName(A_Index) = "Browser tabs")
if (1, oAcc := Acc_Child(oAcc, A_Index))
break
oAcc := Acc_Child(oAcc, 1)

vRet := 0
For each, oChild in Acc_Children(oAcc)
{
if (A_Index = vNum)
if (1, oChild.accDoDefaultAction(0), vRet := A_Index)
break
}

Return vRet
}

;==================================================

JEE_FirefoxFocusTabByName(hWnd, vTitle, vNum=1)
{
oAcc := Acc_Get("Object", "4", 0, "ahk_id " hWnd)
Loop, % oAcc.accChildCount
if (oAcc.accName(A_Index) = "Browser tabs")
if (1, oAcc := Acc_Child(oAcc, A_Index))
break
oAcc := Acc_Child(oAcc, 1)

vCount := 0
vRet := 0
For each, oChild in Acc_Children(oAcc)
{
vTabText := oChild.accName(0)
if (vTabText = vTitle)
vCount ++
if (vCount = vNum)
if (1, oChild.accDoDefaultAction(0), vRet := A_Index)
break
}

oAcc := ""
Return vRet
}

;==================================================

JEE_ChromeGetTabNames(hWnd, vSep="`n")
{
oAcc := Acc_ObjectFromWindow(hWnd)
oAcc := Acc_Child(oAcc, 1), oAcc := Acc_Child(oAcc, 2)
oAcc := Acc_Child(oAcc, 2), oAcc := Acc_Child(oAcc, 2)

vOutput := ""
For each, oChild in Acc_Children(oAcc)
{
vTabText := Acc_Child(oChild, 1).accName(0)
if !(vTabText == "")
vOutput .= vTabText vSep
}
vOutput := SubStr(vOutput, 1, -StrLen(vSep)) ;trim right

oAcc := ""
Return vOutput
}

;==================================================

JEE_ChromeFocusTabByNum(hWnd, vNum)
{
oAcc := Acc_ObjectFromWindow(hWnd)
oAcc := Acc_Child(oAcc, 1), oAcc := Acc_Child(oAcc, 2)
oAcc := Acc_Child(oAcc, 2), oAcc := Acc_Child(oAcc, 2)

vRet := 0
For each, oChild in Acc_Children(oAcc)
{
if (A_Index = vNum+1)
if (1, oChild.accDoDefaultAction(0), vRet := A_Index)
break
}

Return vRet
}

;==================================================

JEE_ChromeFocusTabByName(hWnd, vTitle, vNum=1)
{
oAcc := Acc_ObjectFromWindow(hWnd)
oAcc := Acc_Child(oAcc, 1), oAcc := Acc_Child(oAcc, 2)
oAcc := Acc_Child(oAcc, 2), oAcc := Acc_Child(oAcc, 2)

vCount := 0
vRet := 0
For each, oChild in Acc_Children(oAcc)
{
vTabText := oChild.accName(0)
if (vTabText = vTitle)
vCount ++
if (vCount = vNum)
if (1, oChild.accDoDefaultAction(0), vRet := A_Index)
break
}

oAcc := ""
Return vRet
}

;==================================================