之前介绍过这样的例子,里面用的都是无标题 – 记事本。
^a::
Run, Notepad.exe
Winactivate, 无标题 – 记事本
WinWaitActive, 无标题 – 记事本
Send, 7 lines{!}{enter}
SendInput inside the ctrl{+}j hotkey
Return
#IfWinActive 无标题 – 记事本
!q::
MsgBox, You pressed Alt+Q in Notepad.
Return
:*:]d:: ; 此热字串通过后面的命令把 “]d” 替换成当前日期和时间.
FormatTime, CurrentDateTime,, M/d/yyyy h:mm tt ; 看起来会像 9/1/2005 3:53 PM 这样
SendInput %CurrentDateTime%
return
; 任何不是无标题 – 记事本的窗口
#IfWinActive
!q::
MsgBox, You pressed Alt+Q in any window.
Return
如何获得一个窗口的名称呢?
或者运行一个热键脚本,并右键托盘图标
就会出现这样的一个始终置顶的窗口
它会显示当前处于激活状态的窗口的名称、类别和进程。
默认新建的notepad名称均为无标题 – 记事本,那么如果我想要让我的脚本在任意名称的notepad下均可以工作呢?
我们可以注意到,不论我将记事本命名成什么,他的窗口类别始终是不变的,那么我们就可以这么写
#IfWinActive ahk_class Notepad
#space::
MsgBox, You pressed Win+Spacebar in Notepad.
Return
对于WinActivate等命令均可实现类似的操作,如:
; 激活命令行窗口 (例如 cmd.exe)
WinActivate, ahk_class ConsoleWindowClass