神器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:


 

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:someone@somedomain.com

 

下面第一個例子表示“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官方幫助文檔


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM