神器AutoHotkey学习(官方文档翻译)

Tutorial and Overview

Creating a script

如何创建脚本:

  1. 下载AutoHotkey

  2. 桌面空白处右键新建见本文件“AutoHotkey Script”

  3. 重命名文件,比如“Test.ahk”

  4. 右键“Edit Script”来编辑脚本文件

  5. 空行,输入“#space::Run www.google.com

“#”表示“Win”键,“#space”=Win+space,“::”表示后续指令在按下快捷键后执行。
如何执行:

  1. 保存并关闭文件,双击运行,任务栏会出现新图标

  2. 按下Win+space,会打开新网页“www.google.com”

  3. 右键该图标可选择编辑或退出


Notes:

  • To have a script launch automatically when you start your computer, create a shortcut in the Start Menu's Startup folder.--tdlis

Launching a program or document

“Run”用来运行程序,文档,URL或快捷方式。

Run Notepad
Run C:\My Documents\Address List.doc
Run C:\My Documents\My Shortcut.lnk
Run www.yahoo.com
Run mailto:[email protected]

下面第一个例子表示“Win+N”=打开Notepad

第二个例子表示“Ctl+Alt+C”=打开计算器程序

#n::Run Notepad
^!c::Run calc.exe

单行命令如上。

多行命令需要return,分开写,如下。

#n::
Run http://www.google.com
Run Notepad.exe
return

如果程序不在系统路径中,声明完整的路径

Run %A_ProgramFiles%\Winamp\Winamp.exe

"%A_ProgramFiles%"是“内置变量 built-in variable”,可提升可移植性。而且大小写不敏感。

如果需要使程序继续执行其他动作之前等待,需要“RunWait”。如下面,只有在关闭Notepad之后才会输出消息。

RunWait Notepad
MsgBox The user has finished (Notepad has been closed).

欲知更多,比如“参数传递,声明工作目录,找出程序退出码...” -- click here.

Sending keystrokes and mouse clicks

Keystrokes are sent to the active (foremost) window by using the Send command. In the following example, Control+Alt+S becomes a hotkey to type a signature (ensure that a window such as an editor or draft e-mail message is active before pressing the hotkey):

^!s::
Send Sincerely,{Enter}John Smith
return

In the above example, all characters are sent literally except {Enter}, which simulates a press of the Enter key. The next example illustrates some of the other commonly used special characters:

Send ^c!{tab}pasted:^v

The line above sends a Control+C followed by an Alt+Tab followed by the string "pasted:" followed by a Control+V. See the Send command for a complete list of special characters and keys.

Finally, keystrokes can also be sent in response to abbreviations you type, which are known as hotstrings. For example, whenever you type Btw followed by a space or comma, the following line will replace it with "By the way":

::btw::by the way


Mouse Clicks
: To send a mouse click to a window it is first necessary to determine the X and Y coordinates where the click should occur. This can be done with either AutoScriptWriter or Window Spy, which are included with AutoHotkey. The following steps apply to the Window Spy method:

  1. Launch Window Spy from a script's tray-icon menu or the Start Menu.

  2. Activate the window of interest either by clicking its title bar, alt-tabbing, or other means (Window Spy will stay "always on top" by design).

  3. Move the mouse cursor to the desired position in the target window and write down the mouse coordinates displayed by Window Spy (or on Windows XP and earlier, press Shift-Alt-Tab to activate Window Spy so that the "frozen" coordinates can be copied and pasted).

  4. Apply the coordinates discovered above to the Click command. The following example clicks the left mouse button:
    Click 112, 223

To move the mouse without clicking, use MouseMove. To drag the mouse, use MouseClickDrag.

来源:AutoHotkey官方帮助文档

你可能感兴趣的:(autohotkey)