在 Microsoft Edge 处于活动状态时执行操作的 Autohotkey 脚本

时间:2021-03-28 03:10:58

标签: autohotkey microsoft-edge

我正在尝试编写脚本,以便在 Microsoft Edge 窗口处于活动状态时执行操作。我试过这些脚本:

#IfWinActive Microsoft edge
~$l::
KeyWait,l,T0.25
if (ErrorLevel)
{
 send,^l
 sleep,100
 send,{Delete}
}
return

但它无法识别窗户。我也尝试了不同的名称,例如 #IfWinActive, ahk_class Microsoft Edge#IfWinActive Microsoft Edge.exe。但他们都没有工作。

1 个答案:

答案 0 :(得分:2)

在新的 Edge 选项卡上使用 Window Spy 显示:

enter image description here

在用于 #IfWinActive 语句的三个主要选项(WinTitleahk_classahk_exe)中,ahk_exe 可能是最佳选择用于创建始终在 MS Edge 中工作的脚本,并且仅在基于 Windows Spy 显示内容的 MS Edge 中工作。

基于此,我创建了这个通用脚本来检查是否在 Edge 中触发了热键

#IfWinActive, ahk_exe msedge.exe
^q::MsgBox Hotkey Triggered in Edge (msedge.exe)
#If

^q::MsgBox Hotkey Triggered in a different program

将您的原始脚本并入其中:

#IfWinActive, ahk_exe msedge.exe
~$l::
KeyWait,l,T0.25
if (ErrorLevel)
{
 send,^l
 sleep,100
 send,{Delete}
}
return

有关#IfWinActive 的更多信息,请参阅the docs

也相关:Post on AHK forums on how to use the #IfWinActive with program names, ahk_exe, and ahk_class