如何使用 Autohotkey 专注于现有的 Google Chrome 选项卡,而不是“容器”窗口?

vle*_*hue 19 google-chrome autohotkey

如何使用 Autohotkey 专注于现有的 Google Chrome 选项卡,而不是“容器”窗口?

细节

谷歌浏览器似乎用一个容器窗口句柄来表示每个窗口,其中包含一个或多个选项卡。选项卡(至少是当前的)有自己的窗口句柄。选项卡窗口句柄有窗口标题(目前都以“- Google Chrome”结尾),而容器窗口句柄本身没有。以下自动热键代码不适用于 Google Chrome:

^+i::
if WinExist("ahk_class Chrome_WidgetWin_0")
    WinActivate
else
    Run "C:\Users\vleeshue\AppData\Local\Google\Chrome\Application\chrome.exe"
return
Run Code Online (Sandbox Code Playgroud)

如果 Google Chrome 窗口存在或将运行 Google Chrome,则此绑定将重点放在 Google Chrome 窗口上。但是,它通常会以容器窗口为目标(在 Window Spy 中,窗口标题为空白)。激活容器窗口将禁止使用 Google Chrome 键盘快捷键。无法访问的键盘快捷键包括所有重要的 ctrl+l 以访问多功能栏。由于我还没有找到一致激活选项卡窗口而不是容器窗口的方法,我的解决方法是使用鼠标,但如果可能的话,我更愿意避免这种情况。

窗口间谍截图

容器窗口把手

选项卡窗口句柄

背景

当前 Google Chrome 版本:5.0.317.2 dev

我使用的一个常见的自动热键绑定是一个键盘快捷键,用于聚焦特定应用程序(如果它已经在运行)或运行该应用程序(如果它没有运行)。

例如,我将它用于 foobar2000

^+m::
If WinExist("foobar2000")
    WinActivate
else
    Run "C:\Program Files (x86)\foobar2000\foobar2000.exe"
return
Run Code Online (Sandbox Code Playgroud)

flu*_*ndu 6

^+i::
if WinExist("ahk_class Chrome_WindowImpl_0")
  {
  WinActivate
  ControlFocus, Chrome_AutocompleteEditView1
  }
else
  Run "C:\Users\vleeshue\AppData\Local\Google\Chrome\Application\chrome.exe"
return
Run Code Online (Sandbox Code Playgroud)

应该做的伎俩

(“Chrome_AutocompleteEditView1”是 omnibar 控件的名称,因此您可以添加Send ^a以全选)

注意:要获取ahk_class适用于您的 Chrome 版本的 ,例如ahk_class Chrome_WindowImp1-0,请使用AU3_Spy.exe内部 autohotkey 目录。如果示例不起作用,这将允许您为您的 chrome 浏览器找到正确的 ahk 类。

更新:我无法重现,也许使用另一个控件会更好......要获得窗口控件列表,我使用以下代码:

#Persistent
SetTimer, WatchCursor, 100
return

WatchCursor:
  MouseGetPos, , , id, control
  WinGetTitle, title, ahk_id %id%
  WinGetClass, class, ahk_id %id%
  WinGet, ControlList, ControlList, A
  ToolTip, Under Cursor:`nahk_id: %id%`nahk_class: %class%`nTitle:%title%`nControl: %control%`n`nWindow Control List:`n%ControlList%
return
Run Code Online (Sandbox Code Playgroud)

所以我的 google chrome 4.0.249.78 beta (36714) 的控件是:

  • 视图TextfieldEdit1
  • Chrome_RenderWidgetHostWND1
  • Chrome_AutocompleteEditView1
  • Chrome_WindowImpl_01
  • Chrome_WindowImpl_02


Gre*_*ray 4

您可能想考虑使用 Chrome 扩展程序而不是 AutoHotkey。扩展程序可以访问所有打开的选项卡,包括URL和更改选项卡焦点的功能。否则,您可能需要使用Chrome 中的辅助功能来查询活动窗口。我相信这就是像 RescueTime 这样的程序跟踪活动 URL 的方式。例如,使用 Windows 7 SDK 中的可访问事件观察器 (AccEvent) 在 Chrome 中更改选项卡时会显示以下事件:

谷歌浏览器 AccEvent