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