首页 > 解决方案 > 在 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。但他们都没有工作。

标签: autohotkeymicrosoft-edge

解决方案


在新的 Edge 选项卡上使用 Window Spy 向我展示了这一点:

在此处输入图像描述

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

基于此,我创建了这个通用脚本来检查是否在 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 的更多信息,请参阅文档

也相关:在 AHK 论坛上发布关于如何使用带有程序名称、ahk_exe 和 ahk_class 的#IfWinActive 的帖子


推荐阅读