[AHK-] AutoHotKey 入門教學 - 重複一系列動作

看板EzHotKey作者 (家瑀 致中和)時間16年前 (2008/07/22 18:58), 編輯推噓2(200)
留言2則, 2人參與, 最新討論串1/1
Repeating a series of actions over and over http://www.autohotkey.com/docs/Tutorial.htm#Loop 重複一系列的動作: Loop (也稱為迴圈)指令可以讓 AutoHotKey 一直重複做同一件事情。 下面示範連續顯示同一個 MsgBox 三次: Loop 3 { MsgBox 這個視窗將會顯示三次唷~~ } 關於 MsgBox http://www.autohotkey.com/docs/commands/MsgBox.htm ────────── 你也可以將 Loop 後面的數字改成一個變數, 這樣 Loop 執行的次數將由變數箱子裡的數字的大小來決定: RunCount = 5 Loop %RunCount% { Run C:\Check Server Status.exe Sleep 60000 ; 等待 60 秒,這段綠色不會執行 } 以上面例子來說,除非 RunCount = 0,否則 Loop 都會被執行, 執行次數由 RunCount 數字大小決定,這裡則是執行 5 次。 ────────── 要讓 Loop 停止執行,只要改變它的執行條件就行了。 下面這個 script 會在你按下 F1 時,自動一直按滑鼠左鍵: $F1:: ; 將 F1 設定成快速鍵 ; $ 符號可以幫助下面的 GetKeyState 在模式 P 找到 F1 這個快速鍵. Loop ; 這裡沒有數字, ; 也就是說 Loop 不會停止, 直到在中括號遇到 "return" 或 "break". { ; 如果下面這個 if-表達式 成立, 表示你放開了 F1. if not GetKeyState("F1", "P") break ; 離開這個 Loop. ; 否則 (上面那個 if-表達式 不成立), 執行下面剩下的指令. Click ; 在目前滑鼠位置上按一下左鍵. } return 上面的例子類似其他程式語言的 "while...do" 迴圈。 也就是說,當某些條件被滿足時,Loop 不會停止。 以這個範例來說,當你按下 F1 時,Loop 會一直幫你連按滑鼠左鍵。 一旦你放開 F1GetKeyState 偵測到 F1 沒有被按下,於是 break 被執行, Loop 也就停止了。 這種類型的 Loop 其實是很被廣泛使用的。 關於 break http://www.autohotkey.com/docs/commands/Break.htm ────────── 如果為了特定需求,還可以考慮下列幾種 Loop 類型: 檔案 - 讀取/寫入 迴圈(File-reading/writing loop): 藉由擷取某段文字的特定幾行的方式,一行一行將特定檔案轉換成另一種格式。 也可以用來依照特定條件搜尋符合的某行文字。一次一個。 http://www.autohotkey.com/docs/commands/LoopReadFile.htm 檔案和資料夾迴圈(Files and folders loop): 藉由檔案或資料夾的資訊可以對符合條件的檔案及資料夾做處理。一次一個。 http://www.autohotkey.com/docs/commands/LoopFile.htm Parsing loop: 可以取出一長串文字中的單詞,一次一個。 例如說將 "Red,Green,Blue" 切開成三等分。 http://www.autohotkey.com/docs/commands/LoopParse.htm 登錄檔迴圈: 處理指定的登錄檔項目,一次一個。 http://www.autohotkey.com/docs/commands/LoopReg.htm File-reading/writing loop: Retrieves the lines in a text file, one at a time. This can be used to transform a file into a different format on a line-by-line basis. It can also be used to search for lines matching your criteria. Files and folders loop: Retrieves the specified files or folders, one at a time. This allows an operation to be performed upon each file or folder that meets your criteria. Parsing loop: Retrieves substrings from a string, one at a time. This allows a string such as "Red,Green,Blue" to be easily broken down into its three component fields. Registry loop: Retrieves the contents of the specified registry subkey, one item at a time. -- 主動是機會的誘餌 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 61.62.72.196

07/23 00:27, , 1F
推你 我之前看他說明看半天
07/23 00:27, 1F
※ 編輯: VElysian 來自: 61.62.72.58 (08/01 19:20)

01/06 01:13, , 2F
唔,還是很需要功夫才能理解及操作
01/06 01:13, 2F
※ 編輯: VElysian 來自: 61.62.111.209 (07/12 22:40)
文章代碼(AID): #18XRrU26 (EzHotKey)