如何在不定义热键的情况下自动运行脚本?
问题描述:
我想创建一个“PolyEdit”脚本。 以下是脚本。如何在不定义热键的情况下自动运行脚本?
!M::
IfWinActive, ahk_class TMainForm
{
sleep 2000
Send Now is the time
Return
}
脚本的目的是:
发送键盘和鼠标操作,以我的默认程序打开文本文件。 该默认程序被称为“PolyEdit”。
但我需要脚本运行时没有定义热键。
现在,它是现在的形式,用热键定义,它运行得很好。
我的问题是:
我怎样才能使脚本自动运行,无需热键被定义?
答
由于阿明已经写,使用#Persistent后。另外,如果要创建只在特定应用程序处于焦点状态时处于活动状态的热键,则可以执行以下操作:在这种情况下,脚本将不再在启动时执行,只有当您按热键时才会执行...
#Persistent
#SingleInstance
#IfWinActive, ahk_class TMainForm
!M::
sleep 2000
Send Now is the time
Return
!n::SoundBeep, 500, 500
!o::MsgBox, OK
#IfWinActive
这样,所有3个(虚拟)热键将只在您的应用程序处于焦点时处于活动状态!您可以为其他应用程序定义相同的热键,只需重复该代码,但使用#IfWinActive, ahk_class TMainForm
行中的其他应用程序的ID即可。
如果你想发送一条消息,每2秒的时候,您的应用程序是活动的执行以下操作:
#Persistent
#SingleInstance
SetTimerMatchMode, CheckApp, 2000
Return
CheckApp:
IfWinActive, ahk_class TMainForm
{
Send, Now is the time
}
Return
如果你希望每次(重新)时激活(把聚焦)执行脚本您应用程序(所以不是每两秒)然后使用以下内容:
#Persistent
#installKeybdHook
#SingleInstance
Gui +LastFound
hWnd := WinExist()
DllCall("RegisterShellHookWindow", UInt,Hwnd)
MsgNum := DllCall("RegisterWindowMessage", Str,"SHELLHOOK")
OnMessage(MsgNum, "ShellMessage")
Return
ShellMessage(wParam)
{
If (wParam = 4)
{
IfWinActive ahk_class TMainForm
{
Send, Now is the time
}
}
}
Return