AutoHotkey-個人實例解釋

  • 基礎知識:
#表明win,+表明shift,^表明Ctrl,!表明Alt,LButton和RButton分別表明左右按鍵,~表示按住後面的按鍵(~LButton表示按住左鍵)。
其餘按鍵能夠直接用原字符,組合按鍵大多數能夠直接相連(#V表示win+v),多字符的按鍵相連時能夠用{}區分字符(!{Tab}表示Alt+Tab),鼠標之間組合能夠使用&(~LButton & RButton 按住左右鍵 (更確切的說是按住左鍵的同時,按下右鍵。)
註釋是;在行首
(推薦SciTE4AutoHotkey做爲IDE
  • 組合按鍵運行應用
按下Win+V運行Emeditor:
  1. #v::
  2. run "D:\Program Files\EmEditor\EmEditor.exe"
  3. return
run的效果就至關於在運行裏面執行的效果,能夠是exe,能夠是打開文件夾。
 
來個鼠標的:
按住左右鍵(更確切的說是按住左鍵的同時,按下右鍵。)運行VistaSwitcher
  1. ~LButton&RButton::
  2. run "D:\Program Files\VistaSwitcher\vswitch64.exe"
  3. return
 
  • 組合鍵相互替換
windows有一些默認的組合鍵很經常使用,可是位置比較着急。能夠用組合鍵替換之。
 
用win+w來替換alt+t,(alt+t在windows中是預覽任務欄的功能)
  1. #w::
  2. send #t
  3. return
就一個send命令!
 
  • 進階一點點:
顯然如此簡單的功能低估了autohotkey,autohotkey也能夠有變量有函數有複雜語句:
  1. if(){}
  2. elseif(){}
  3. else{}
 
是最經常使用的,注意判斷是=,而非==
 
還能夠聲明變量,若是是全局的,在ahk文件的最上面聲明最好。
 
  • 操做Windows窗口
這個地方用到的api比較多,推薦 《Autohotkey-命令列表》
 
讓當前窗口最小化:
  1. #M::
  2. WinMinimize A
  3. ;WinMinimize最小化命令,A表示當前窗口
  4. return
經過變量讓全部窗口最小化或者撤銷:
  1. wind =0
  2. ;win+d to Minimize all windows and undo
  3. #D::
  4. ;MsgBox,%wind%
  5. ;use the variable to decide minimize or undo
  6. if(wind =0)
  7. {
  8. WinMinimizeAll
  9. wind =1
  10. }
  11. elseif(wind =1)
  12. {
  13. WinMinimizeAllUndo
  14. wind =0
  15. }
  16. return
MsgBox是彈出提示框,後面的是字符,帶%%就能夠表示變量了。
更復雜一點的,操做指定的窗口: 若是沒有這個窗口,則打開exe。若是有,且再也不前臺的話,激活到前臺。若是在前臺,關閉之。
注意一下的Win操做,都是對窗口標題的檢測!!與後面的進程操做不同。
  1. ;win+X to run SpeedCrunch
  2. #X::
  3. IfWinActive,SpeedCrunch
  4. WinClose,SpeedCrunch
  5. Else
  6. IfWinExist,SpeedCrunch
  7. WinActivate,SpeedCrunch
  8. Else
  9. Run"C:\Program Files\SpeedCrunch\speedcrunch.exe"
  10. Return
 
  • 操做進程
現實中有些windows程序是沒有窗口標題,或者窗口標題變化,有的甚至沒有窗口,這時候須要經過進程來來操做。
經過進程打開evernote,並實現前臺後臺切換。
  1. ;;win+] to run evernote and hide
  2. Process,Exist,Evernote.exe
  3. if(ErrorLevel=0)
  4. {
  5. Run"D:\Program Files\Evernote\Evernote\Evernote.exe"
  6. }
  7. else
  8. {
  9. ;there is to show how to use pid to active and hide
  10. IfWinNotActive ahk_pid %ErrorLevel%
  11. Send^!b
  12. ;if evernote is not in front, use its default shortcut key 
  13. else
  14. WinClose ahk_pid %ErrorLevel%
  15. ;if it is in front, close it 
  16. }
經過Process, Exist 獲得是進程pid,存在ErrorLevel中,沒有則爲0。
 
能夠直接去看個人github。
 
 
 
 





附件列表

相關文章
相關標籤/搜索