神器AutoHotkey學習(官方文檔翻譯)

 

Tutorial and Overview


 

Creating a script

如何建立腳本:app

  1. 下載AutoHotkeydom

  2. 桌面空白處右鍵新建見本文件「AutoHotkey Script」ui

  3. 重命名文件,好比「Test.ahk」google

  4. 右鍵「Edit Script」來編輯腳本文件spa

  5. 空行,輸入「#space::Run www.google.comrest

「#」表示「Win」鍵,「#space」=Win+space,「::」表示後續指令在按下快捷鍵後執行。
如何執行:htm

  1. 保存並關閉文件,雙擊運行,任務欄會出現新圖標ip

  2. 按下Win+space,會打開新網頁「www.google.com」ci

  3. 右鍵該圖標可選擇編輯或退出rem

 

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官方幫助文檔

相關文章
相關標籤/搜索