標籤:

AutoHotKey 常用函數或小技巧有哪些分享?

大家可以把自己覺得有用的函數,或者小技巧共享給大家。

定義熱字元串:

:*:string:: 輸入完後直接執行,無需空格,回車,tab鍵

:*b0:string:: 禁用退格鍵


;放上自己的一套腳本,自定義了一些功能,寫代碼基本手不用離開鍵盤,特別是方向鍵,基本定;位在了jkli 中,上翻下翻面,刪除,選擇扒拉扒拉,自己選著用吧!

;url編碼解碼

uriEncode(str) {

f = %A_FormatInteger%

SetFormat, Integer, Hex

If RegExMatch(str, "^w+:/{0,2}", pr)

StringTrimLeft, str, str, StrLen(pr)

StringReplace, str, str, `%, `%25, All

Loop

If RegExMatch(str, "i)[^w.~%]", char)

StringReplace, str, str, %char%, % "%" . Asc(char), All

Else Break

SetFormat, Integer, %f%

Return, pr . str

}

uriDecode(str) {

Loop

If RegExMatch(str, "i)(?&<=%)[da-f]{1,2}", hex)

StringReplace, str, str, `%%hex%, % Chr("0x" . hex), All

Else Break

Return, str

}

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;快速命令;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

:://g::

Run http://www.google.com

return

:://b::

Run http://www.baidu.com

return

:://s::

Run C:Program FilesEverythingEverything.exe

return

:://qq::

Run C:Program FilesTencentQQBinQQ.exe

return

:://cmd::

Run cmd

return

:://n::

Run notepad

return

:://d::

Run C:Program Fileshttp://dict.cnDianDian.exe

return

:://e::

Run explorer

return

;打開任務管理器

:://t::

if WinExist Windows 任務管理器

WinActivate

else

Run taskmgr.exe

return

;一些經常輸入的字元串

:://m::

Send babyking1949@gmail.com

return

;打開系統屬性

:://sys::

Run control sysdm.cpl

return

;打開autohotkey 配置文件

:://ahk::

Run D:GreenSoftAutoHotKey 中文版AutoHotKey.ini

return

;;;;;;;;;;快速打開程序(快捷鍵);;;;;;;;;;;;;;;;;;;;;;;;;

;用google搜索

!g::

Send ^c

Run http://www.google.com/search?q=%clipboard%

return

;用百度搜索

!b::

Send ^c

Run http://www.baidu.com/s?wd=%clipboard%

return

!t::

Send ^c

Run http://s.taobao.com/search?q=%clipboard%

return

;快速打開記事本

#n::

If WinExist Untitled - Notepad

WinActivate

else

Run Notepad

return

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;通用鍵的映射;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;對windows下的一些常用鍵進行映射,與蘋果下的一些習慣一樣(蘋果下的快捷鍵有些非常合理:)

!f::Send ^f ;查找

!q:: !F4 ;退出

!w::Send ^w ;關閉網頁窗口

!r::Send #r

!s::Send ^s ;保存

!n::Send ^n ;新建

!z::Send ^z

;選擇文字

!,::Send ^+{Left}

!.::Send ^+{Right}

return

!y:: Send+{Home} ;選擇當前位置到行首的文字

!p:: Send +{End} ;選擇當前位置到行末的文字

;選擇一行

!a::

Send {Home}

Send +{End}

return

;滑鼠的左右鍵實現任務切換,對thinkpad trackpoint 特別有用

~LButton RButton::AltTab

~LButton MButton::MsgBox,hello

;&<短時間雙擊alt鍵切換capslock鍵&>

;~ 設置一個時鐘,比如400 毫秒,

;~ 設置一個計數器,Alt_presses,按擊次數,每次響應時鐘把計數器清0複位

#Persistent

$Alt::

if Alt_presses &> 0 ; SetTimer 已經啟動,所以我們記錄按鍵。

{

Alt_presses += 1

return

}

;否則,這是新一系列按鍵的首次按鍵。將計數設為 1 並啟動定時器:

Alt_presses = 1

SetTimer, KeyAlt, 300 ;在 300 毫秒內等待更多的按鍵。

return

KeyAlt:

SetTimer, KeyAlt, off

if Alt_presses = 1 ;該鍵已按過一次。

{

Gosub singleClick

}

else if Alt_presses = 2 ;該鍵已按過兩次。

{

Gosub doubleClick

}

;不論上面哪個動作被觸發,將計數複位以備下一系列的按鍵:

Alt_presses = 0

return

singleClick:

send {alt}

return

doubleClick:

if GetKeyState("Capslock", "T")

SetCapsLockState,off

else

SetCapsLockState,on

return

;&

;copy cut paste 的快捷鍵

!c::Send ^c

!x::Send ^x

!v::Send ^v

;上頁翻頁鍵映射

!h::Send {PgUp}

!;::Send {PgDn}

;HOME END鍵映射

!u:: Send {Home} ;

!o:: Send {End} ;

;Alt + jkli 實現對方向鍵的映射,寫代碼的時候灰常有用

!j:: Send {left}

!l:: Send {right}

!i:: Send {up}

!k:: Send {down}

;Delete Backspace的映射

;!f::Send {Backspace}

!d::Send {Delete}

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;通用鍵的映射;(結束);;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;實用功能;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;win鍵 + PrintScreen鍵關閉屏幕

#PrintScreen::

KeyWait PrintScreen

KeyWait LWin ;釋放左Win鍵才激活下面的命令

SendMessage,0x112,0xF170,2,,Program Manager ;關閉顯示器。0x112:WM_SYSCOMMAND,0xF170:SC_MONITORPOWER。2:關閉,-1:開啟顯示器

Return

/*

;雙擊滑鼠右鍵在窗口最大化與正常狀態之間切換

WinStatus:=0

RButton::

KeyWait, RButton ;鬆開滑鼠右鍵後才繼續執行下面的代碼

keyWait, RButton, D T0.15 ;在 100 毫秒內等待再次按下滑鼠右鍵,可以設置一個自己覺得適合的等待時間。

If ErrorLevel

Click, Right

Else

{

if WinStatus=0

{

WinMaximize , A

WinStatus:=1

}

else

{

WinRestore ,A

WinStatus:=0

}

}

Return

!m::

if WinStatus=0

{

WinMaximize , A

WinStatus:=1

}

else

{

WinRestore ,A

WinStatus:=0

}

return

;命令行cmd里可以ctrl v

#IfWinActive ahk_class ConsoleWindowClass

^v::

MouseClick, Right, %A_CaretX%, %A_CaretY%,,0

send p

return

*/

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;實用功能(結束);;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;&;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

#IfWinActive ahk_class Chrome_WidgetWin_0

!,::Send ^+{Tab}

!.::Send ^{Tab}

!1::Send ^+{Tab}

!2::Send ^{Tab}

!n::Send ^t

!/::Send ^w

!z::Send ^+t

!-::Send ^-

!=::Send ^=

;選擇當前位置到頁尾的文字,適用於瀏覽器

F2::

Send ^+{End}

;Send ^c

return

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;&<資源管理器&>;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

#IfWinActive ahk_class CabinetWClass

!f::

Run C:Program FilesEverythingEverything.exe

return

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;&;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

#IfWinActive ahk_class Notepad

;!u::Send ^{Home}

;!o::Send ^{End}

return

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;&;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

#IfWinActive,Eclipse

!.::Send ^{F8}

return

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;&;;;;;;;;;;;;;;;;;;;;;;;

#IfWinActive ahk_class wndclass_desked_gsk

!/::Send ^{Tab}

!.::Send ^+{Tab}

!m::Send !+{Enter}

return

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;&;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;&;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

#IfWinActive ahk_class OfficeTooltip

!u::Send ^{Home}

!o::Send ^{End}

return


自己寫的一個AHK小腳本,專門用來增加CapsLock功能的。

比起單純的映射CapsLock到ESC或者Ctrl,我認為還是有很大的定製性優勢的。

主要功能包括:Vim式游標移動,Win式編輯器常用快捷鍵,媒體控制,滑鼠移動等等等等。

還有一些IDE特定的按鍵綁定。都可以按自己的需求修改。

啊,當然最重要的是capslock本身變成了ESC……對於Vim黨真是大福音。

本身是Windows下用的,當然SSH,虛擬機里的Linux也能用,而且用起來更爽……

地址:Vonng/Configuration · GitHub

設計過程思路見:

CapsLock魔改大法——變廢為寶實現高效編輯

CapsLock Enhancement via AutoHotKey

代碼也貼這裡算了:

;=====================================================================o
; Feng Ruohang"s AHK Script |
; CapsLock Enhancement |
;---------------------------------------------------------------------o
;Description: |
; This Script is wrote by Feng Ruohang via AutoHotKey Script. It |
; Provieds an enhancement towards the "Useless Key" CapsLock, and |
; turns CapsLock into an useful function Key just like Ctrl and Alt |
; by combining CapsLock with almost all other keys in the keyboard. |
; |
;Summary: |
;o----------------------o---------------------------------------------o
;|CapsLock; | {ESC} Especially Convient for vim user |
;|CaspLock + ` | {CapsLock}CapsLock Switcher as a Substituent|
;|CapsLock + hjklwb | Vim-Style Cursor Mover |
;|CaspLock + uiop | Convient Home/End PageUp/PageDn |
;|CaspLock + nm,. | Convient Delete Controller |
;|CapsLock + zxcvay | Windows-Style Editor |
;|CapsLock + Direction | Mouse Move |
;|CapsLock + Enter | Mouse Click |
;|CaspLock + {F1}!{F7} | Media Volume Controller |
;|CapsLock + qs | Windows Tags Control |
;|CapsLock + ;"[] | Convient Key Mapping |
;|CaspLock + dfert | Frequently Used Programs (Self Defined) |
;|CaspLock + 123456 | Dev-Hotkey for Visual Studio (Self Defined) |
;|CapsLock + 67890-= | Shifter as Shift |
;-----------------------o---------------------------------------------o
;|Use it whatever and wherever you like. Hope it help |
;=====================================================================o

;=====================================================================o
; CapsLock Initializer ;|
;---------------------------------------------------------------------o
SetCapsLockState, AlwaysOff ;|
;---------------------------------------------------------------------o

;=====================================================================o
; CapsLock Switcher: ;|
;---------------------------------o-----------------------------------o
; CapsLock + ` | {CapsLock} ;|
;---------------------------------o-----------------------------------o
CapsLock `:: ;|
GetKeyState, CapsLockState, CapsLock, T ;|
if CapsLockState = D ;|
SetCapsLockState, AlwaysOff ;|
else ;|
SetCapsLockState, AlwaysOn ;|
KeyWait, `` ;|
return ;|
;---------------------------------------------------------------------o

;=====================================================================o
; CapsLock Escaper: ;|
;----------------------------------o----------------------------------o
; CapsLock | {ESC} ;|
;----------------------------------o----------------------------------o
CapsLock::Send, {ESC} ;|
;---------------------------------------------------------------------o

;=====================================================================o
; CapsLock Direction Navigator ;|
;-----------------------------------o---------------------------------o
; CapsLock + h | Left ;|
; CapsLock + j | Down ;|
; CapsLock + k | Up ;|
; CapsLock + l | Right ;|
; Ctrl, Alt Compatible ;|
;-----------------------------------o---------------------------------o
CapsLock h:: ;|
if GetKeyState("control") = 0 ;|
{ ;|
if GetKeyState("alt") = 0 ;|
Send, {Left} ;|
else ;|
Send, +{Left} ;|
return ;|
} ;|
else { ;|
if GetKeyState("alt") = 0 ;|
Send, ^{Left} ;|
else ;|
Send, +^{Left} ;|
return ;|
} ;|
return ;|
;-----------------------------------o ;|
CapsLock j:: ;|
if GetKeyState("control") = 0 ;|
{ ;|
if GetKeyState("alt") = 0 ;|
Send, {Down} ;|
else ;|
Send, +{Down} ;|
return ;|
} ;|
else { ;|
if GetKeyState("alt") = 0 ;|
Send, ^{Down} ;|
else ;|
Send, +^{Down} ;|
return ;|
} ;|
return ;|
;-----------------------------------o ;|
CapsLock k:: ;|
if GetKeyState("control") = 0 ;|
{ ;|
if GetKeyState("alt") = 0 ;|
Send, {Up} ;|
else ;|
Send, +{Up} ;|
return ;|
} ;|
else { ;|
if GetKeyState("alt") = 0 ;|
Send, ^{Up} ;|
else ;|
Send, +^{Up} ;|
return ;|
} ;|
return ;|
;-----------------------------------o ;|
CapsLock l:: ;|
if GetKeyState("control") = 0 ;|
{ ;|
if GetKeyState("alt") = 0 ;|
Send, {Right} ;|
else ;|
Send, +{Right} ;|
return ;|
} ;|
else { ;|
if GetKeyState("alt") = 0 ;|
Send, ^{Right} ;|
else ;|
Send, +^{Right} ;|
return ;|
} ;|
return ;|
;---------------------------------------------------------------------o

;=====================================================================o
; CapsLock Home/End Navigator ;|
;-----------------------------------o---------------------------------o
; CapsLock + i | Home ;|
; CapsLock + o | End ;|
; Ctrl, Alt Compatible ;|
;-----------------------------------o---------------------------------o
CapsLock i:: ;|
if GetKeyState("control") = 0 ;|
{ ;|
if GetKeyState("alt") = 0 ;|
Send, {Home} ;|
else ;|
Send, +{Home} ;|
return ;|
} ;|
else { ;|
if GetKeyState("alt") = 0 ;|
Send, ^{Home} ;|
else ;|
Send, +^{Home} ;|
return ;|
} ;|
return ;|
;-----------------------------------o ;|
CapsLock o:: ;|
if GetKeyState("control") = 0 ;|
{ ;|
if GetKeyState("alt") = 0 ;|
Send, {End} ;|
else ;|
Send, +{End} ;|
return ;|
} ;|
else { ;|
if GetKeyState("alt") = 0 ;|
Send, ^{End} ;|
else ;|
Send, +^{End} ;|
return ;|
} ;|
return ;|
;---------------------------------------------------------------------o

;=====================================================================o
; CapsLock Page Navigator ;|
;-----------------------------------o---------------------------------o
; CapsLock + u | PageUp ;|
; CapsLock + p | PageDown ;|
; Ctrl, Alt Compatible ;|
;-----------------------------------o---------------------------------o
CapsLock u:: ;|
if GetKeyState("control") = 0 ;|
{ ;|
if GetKeyState("alt") = 0 ;|
Send, {PgUp} ;|
else ;|
Send, +{PgUp} ;|
return ;|
} ;|
else { ;|
if GetKeyState("alt") = 0 ;|
Send, ^{PgUp} ;|
else ;|
Send, +^{PgUp} ;|
return ;|
} ;|
return ;|
;-----------------------------------o ;|
CapsLock p:: ;|
if GetKeyState("control") = 0 ;|
{ ;|
if GetKeyState("alt") = 0 ;|
Send, {PgDn} ;|
else ;|
Send, +{PgDn} ;|
return ;|
} ;|
else { ;|
if GetKeyState("alt") = 0 ;|
Send, ^{PgDn} ;|
else ;|
Send, +^{PgDn} ;|
return ;|
} ;|
return ;|
;---------------------------------------------------------------------o

;=====================================================================o
; CapsLock Mouse Controller ;|
;-----------------------------------o---------------------------------o
; CapsLock + Up | Mouse Up ;|
; CapsLock + Down | Mouse Down ;|
; CapsLock + Left | Mouse Left ;|
; CapsLock + Right | Mouse Right ;|
; CapsLock + Enter(Push Release) | Mouse Left Push(Release) ;|
;-----------------------------------o---------------------------------o
CapsLock Up:: MouseMove, 0, -10, 0, R ;|
CapsLock Down:: MouseMove, 0, 10, 0, R ;|
CapsLock Left:: MouseMove, -10, 0, 0, R ;|
CapsLock Right:: MouseMove, 10, 0, 0, R ;|
;-----------------------------------o ;|
CapsLock Enter:: ;|
SendEvent {Blind}{LButton down} ;|
KeyWait Enter ;|
SendEvent {Blind}{LButton up} ;|
return ;|
;---------------------------------------------------------------------o

;=====================================================================o
; CapsLock Deletor ;|
;-----------------------------------o---------------------------------o
; CapsLock + n | Ctrl + Delete (Delete a Word) ;|
; CapsLock + m | Delete ;|
; CapsLock + , | BackSpace ;|
; CapsLock + . | Ctrl + BackSpace ;|
;-----------------------------------o---------------------------------o
CapsLock ,:: Send, {Del} ;|
CapsLock .:: Send, ^{Del} ;|
CapsLock m:: Send, {BS} ;|
CapsLock n:: Send, ^{BS} ;|
;---------------------------------------------------------------------o

;=====================================================================o
; CapsLock Editor ;|
;-----------------------------------o---------------------------------o
; CapsLock + z | Ctrl + z (Cancel) ;|
; CapsLock + x | Ctrl + x (Cut) ;|
; CapsLock + c | Ctrl + c (Copy) ;|
; CapsLock + v | Ctrl + z (Paste) ;|
; CapsLock + a | Ctrl + a (Select All) ;|
; CapsLock + y | Ctrl + z (Yeild) ;|
; CapsLock + w | Ctrl + Right(Move as [vim: w]);|
; CapsLock + b | Ctrl + Left (Move as [vim: b]);|
;-----------------------------------o---------------------------------o
CapsLock z:: Send, ^z ;|
CapsLock x:: Send, ^x ;|
CapsLock c:: Send, ^c ;|
CapsLock v:: Send, ^v ;|
CapsLock a:: Send, ^a ;|
CapsLock y:: Send, ^y ;|
CapsLock w:: Send, ^{Right} ;|
CapsLock b:: Send, ^{Left} ;|
;---------------------------------------------------------------------o

;=====================================================================o
; CapsLock Media Controller ;|
;-----------------------------------o---------------------------------o
; CapsLock + F1 | Volume_Mute ;|
; CapsLock + F2 | Volume_Down ;|
; CapsLock + F3 | Volume_Up ;|
; CapsLock + F3 | Media_Play_Pause ;|
; CapsLock + F5 | Media_Prev ;|
; CapsLock + F6 | Media_Next ;|
; CapsLock + F7 | Media_Stop ;|
;-----------------------------------o---------------------------------o
CapsLock F1:: Send, {Volume_Mute} ;|
CapsLock F2:: Send, {Volume_Down} ;|
CapsLock F3:: Send, {Volume_Up} ;|
CapsLock F4:: Send, {Media_Play_Pause} ;|
CapsLock F5:: Send, {Media_Prev} ;|
CapsLock F6:: Send, {Media_Next} ;|
CapsLock F7:: Send, {Media_Stop} ;|
;---------------------------------------------------------------------o

;=====================================================================o
; CapsLock Window Controller ;|
;-----------------------------------o---------------------------------o
; CapsLock + s | Ctrl + Tab (Swith Tag) ;|
; CapsLock + q | Ctrl + W (Close Tag) ;|
; (Disabled) Alt + CapsLock + s | AltTab (Swith Windows) ;|
; Alt + CapsLock + q | Alt + F4 (Close Windows) ;|
; CapsLock + g | AppsKey (Menu Key) ;|
;-----------------------------------o---------------------------------o
CapsLock s::Send, ^{Tab} ;|
;-----------------------------------o ;|
CapsLock q:: ;|
if GetKeyState("alt") = 0 ;|
{ ;|
Send, ^w ;|
} ;|
else { ;|
Send, !{F4} ;|
return ;|
} ;|
return ;|
;-----------------------------------o ;|
CapsLock g:: Send, {AppsKey} ;|
;---------------------------------------------------------------------o

;=====================================================================o
; CapsLock Self Defined Area ;|
;-----------------------------------o---------------------------------o
; CapsLock + d | Alt + d(Dictionary) ;|
; CapsLock + f | Alt + f(Search via Everything);|
; CapsLock + e | Open Search Engine ;|
; CapsLock + r | Open Shell ;|
; CapsLock + t | Open Text Editor ;|
;-----------------------------------o---------------------------------o
CapsLock d:: Send, !d ;|
CapsLock f:: Send, !f ;|
CapsLock e:: Run http://cn.bing.com/ ;|
CapsLock r:: Run Powershell ;|
CapsLock t:: Run C:Program Files (x86)Notepad++
otepad++.exe ;|
;---------------------------------------------------------------------o

;=====================================================================o
; CapsLock Char Mapping ;|
;-----------------------------------o---------------------------------o
; CapsLock + ; | Enter (Cancel) ;|
; CapsLock + " | = ;|
; CapsLock + [ | Back (Visual Studio) ;|
; CapsLock + ] | Goto Define (Visual Studio) ;|
; CapsLock + / | Comment (Visual Studio) ;|
; CapsLock + | Uncomment (Visual Studio) ;|
; CapsLock + 1 | Build and Run(Visual Studio) ;|
; CapsLock + 2 | Debuging (Visual Studio) ;|
; CapsLock + 3 | Step Over (Visual Studio) ;|
; CapsLock + 4 | Step In (Visual Studio) ;|
; CapsLock + 5 | Stop Debuging(Visual Studio) ;|
; CapsLock + 6 | Shift + 6 ^ ;|
; CapsLock + 7 | Shift + 7 ;|
; CapsLock + 8 | Shift + 8 * ;|
; CapsLock + 9 | Shift + 9 ( ;|
; CapsLock + 0 | Shift + 0 ) ;|
;-----------------------------------o---------------------------------o
CapsLock `;:: Send, {Enter} ;|
CapsLock ":: Send, = ;|
CapsLock [:: Send, ^- ;|
CapsLock ]:: Send, {F12} ;|
;-----------------------------------o ;|
CapsLock /:: ;|
Send, ^e ;|
Send, c ;|
return ;|
;-----------------------------------o ;|
CapsLock :: ;|
Send, ^e ;|
Send, u ;|
return ;|
;-----------------------------------o ;|
CapsLock 1:: Send,^{F5} ;|
CapsLock 2:: Send,{F5} ;|
CapsLock 3:: Send,{F10} ;|
CapsLock 4:: Send,{F11} ;|
CapsLock 5:: Send,+{F5} ;|
;-----------------------------------o ;|
CapsLock 6:: Send,+6 ;|
CapsLock 7:: Send,+7 ;|
CapsLock 8:: Send,+8 ;|
CapsLock 9:: Send,+9 ;|
CapsLock 0:: Send,+0 ;|
;---------------------------------------------------------------------o


看到幾位朋友分享的腳本,我覺得很有現實意義。雖然簡單,但實用。

我這裡不分享技巧(感覺不太合適),只分享幾個也許會有你需要的技巧的集中營:

  1. AutoHotkey幫助:不論是初學還是平時參考,它都讓我受益無窮,其中有大量實用的技巧,需要時信手拈來。有事沒事時看看,熟悉了才會發現這是個藏寶地(對於許多人大概明珠暗投了,所以多強調也不過分)。下載最新的中文幫助:http://ahkcn.github.io/docs
  2. AutoHotkey官方論壇和中文論壇:這是學習AutoHotkey的樂園。面對大量拿來即用的腳本和函數,是不是感覺自己像掉入了米缸的老鼠?是不是技巧自己判斷吧。可嘆的是官方論壇和中文論壇多經變遷,許多好東西也變成了歷史塵埃了。
  3. 搜索引擎:別人認為的技巧你可能並不需要,你需要時候的技巧才成其為技巧,所以在遇到問題時多搜索吧。

---------------------------------------------------------------------------------------

純興趣而言,如果是某種特別的寫法或特殊的演算法這方面的技巧,推薦一個去處:

Category:AutoHotkey(羅賽塔任務)

保證讓你眼花繚亂,當然,若有能力也可寫幾個做點貢獻~


接觸Autohotkey時間不長,只懂簡單的腳本。我設置的開機啟動項「自定義的系統快捷鍵」,用win和26個字母的組合(按鍵盤順序)基本能滿足常用程序的需求。共享下,互相學習。

打開的程序依次為:QQ,新浪微博,資源管理器,「運行」對話框,推特,youtube,放大鏡,irfanview,outlook,picasa3,翻@強代理,strokeit滑鼠手勢,顯示桌面,谷歌閱讀器,我的主頁美味書籤,善用佳軟,Kmplayer,靈格斯詞霸,知乎,totalcommander,系統內置計算器,gvim,evernote,網易163郵箱。

;win+q,Run QQ

#q::

Run "D:Program FilesTencentQQBinQQ.exe"

Return

;win+w,Run Sina Weblog

#w::

Run "http://weibo.com/u/1611556321"

Return

;win+e,Run Explorer

;win+r,打開「運行」對話框

;win+t,Open Twitter

#t::

Run "https://twitter.com/"

Return

;win+y,Open Youtube。

#y::

Run "http://www.youtube.com/"

Return

;win+u,打開「輔助工具管理器」,系統默認。

;win+i,Run irfanview。

#i::

Run "D:Program FilesIrfanViewi_view32.exe"

Return

;win+o,Run OUTLOOK

#o::

Run "D:Program FilesMicrosoft OfficeOffice14OUTLOOK.EXE"

Return

;win+p,Run picasa3

#p::

Run "D:Program FilesGooglePicasa3Picasa3.exe"

Return

;win+a,Run agent。

#a::

Run "D:360Downloads代翻goagent-1.0牆理goagentlocalgoagent.exe"

Return

;win+s,Run Strokeit

#s::

Run "D:360DownloadsStrokeIt2011.10.3更新版StrokeItstrokeit.exe"

Return

;win+d,Show Desktop

;win+f, if "EveryThing" already open, activate it, otherwise, open it.

#f::

IfWinExist "Everything"

WinActivate

else

Run "D:360DownloadsEverything-1.2.1.371Everything-1.2.1.371.exe"

Return

;win+g,Login GoogleReader

#g::

Run "https://www.google.com/reader/view"

Return

;win+h,登錄Home主頁美味書籤。

#h::

Run "C:Documents and SettingsAdministratorLocal SettingsApplication DataGoogleChromeApplicationchrome.exe"

Return

;win+j,Open xbeta

#j::

Run "http://xbeta.info/"

Return

;win+k,Run Kmplayer

#k::

Run "D:Program FilesThe KMPlayerKMPlayer.exe"

Return

;win+l, if "Lingoes" already open, activate it, otherwise, open it.

#l::

IfWinExist LINGOES

WinActivate

else

Run "D:Program FilesLingoesTranslator2Lingoes.exe"

Return

;win+z,打開「知乎」網頁。

#z::

Run "http://www.zhihu.com/read"

Return

;win+x, if "TotalCommander" already open, activate it, otherwise, open it.打開TC:未啟動則啟動之,未激活則激活之,已正常則最小化。

#x::

DetectHiddenWindows, on

IfWinNotExist ahk_class TTOTAL_CMD

Run "D:study otalcmdTOTALCMD.EXE"

Else

IfWinNotActive ahk_class TTOTAL_CMD

WinActivate

Else

WinMinimize

Return

;win+c,Run calc

#c::Run Calc

;win+v, if vim already open, activate it, otherwise, open it.

#v::

IfWinExist ahk_class Vim

WinActivate

else

Run "D:/Program Files/Vim/Vim73/gvim.exe"

Return

;win+n, if "EverNote" already open, activate it, otherwise, open it.

#n::

DetectHiddenWindows, on

IfWinNotExist " Evernote"

Run "D:Program FilesEvernoteEvernoteEvernote.exe"

Else

IfWinNotActive " Evernote"

WinActivate

Else

WinMinimize

Return

;win+m,Run mail163

#m::

Run,http://mail.163.com

WinWait, 163網易免費郵--中文郵箱第一品牌 - Google Chrome,

IfWinNotActive, 163網易免費郵--中文郵箱第一品牌 - Google Chrome, , WinActivate, 163網易免費郵--中文郵箱第一品牌 - Google Chrome,

WinWaitActive, 163網易免費郵--中文郵箱第一品牌 - Google Chrome,

sleep,1000

MouseClick, left, 650, 324

Sleep, 100

Send, 你的密碼

MouseClick, left, 659, 446

Sleep, 100

Return


AHK 最方便的地方在於:

1. 可以很容易地處理按鍵相關的操作,比如按某些鍵執行某些功能。

2. 可以用最簡單的環境(僅需要一個不足1M的AutoHotkey.exe,加一個順手的編輯器),就可以開發不複雜的圖形界面軟體(用其他語言或者開發工具一般要安裝體積龐大的環境才可以開發)。

3. 可以很方便地調用COM對象和Win32 API。

但AHK語法本身在處理複雜的邏輯上不是很順手,功能上也有缺失,函數庫不是很全面,經常需要上網搜代碼來用,所以需要揚長避短。

舉幾個適合使用 AHK 開發的例子。

一個小工具 GKey(Global key):

我們經常有這樣的場景,上網或者看文檔時複製了一段文本,然後需要對這些文本做些處理,比如繁體轉簡體、查字典、文本作為命令運行、用記事本打開做簡單編輯等。也可能突然想起來運行某個不常用的軟體,用菜單找太慢,映射快捷鍵還記不住,如果有個提示就沒問題了。

於是寫了這樣一個小工具。

把它映射到一個常用的快捷鍵(比如Win + j)。運行起來後,會在上面的編輯框顯示剪切板內容。下方是快捷鍵對應的操作,如果有不常用的軟體,也可以放進去。

這樣一個小軟體,主程序只需要60行代碼,甚至用記事本寫也毫不費事,換用其他語言就會麻煩很多。

功能部分顯然不是一成不變的,它有一個配置文件,你可以在裡邊隨意添加功能。比如加一個用百度搜索剪切板內容的功能,映射到 b 按鍵,只需要在GKey.conf里添加幾行行:

@("b", "SearchWithBaidu", "用百度搜索")

SearchWithBaidu:

Run, https://www.baidu.com/s?wd=%clipboard%

return

非常方便。

當然這只是一個小工具,使用的場景也比較有限,下面推薦一個重量級的軟體,VimDesktop。

GitHub - goreliu/vimdesktop: 讓所有 Windows 桌面程序擁有 Vim 操作風格的輔助工具

簡單說,就是讓任何軟體支持類 Vim 按鍵綁定。它重點支持的是 Total Commander,對 TC 常用功能映射了幾乎所有的快捷鍵(全部小寫、大寫、Ctrl + 小寫、F1~F12、大部分符號鍵):

TC快捷鍵列表 · goreliu/vimdesktop Wiki · GitHub

TC快捷鍵列表(字母順序) · goreliu/vimdesktop Wiki · GitHub

所有的按鍵都是可以自定義的,在配置文件中隨意調整。這得益於 TC 幾乎將所有的功能介面暴露出來,可以隨意調用。(很多其他軟體界面看起來和 TC 差不多,甚至粗看功能也很強大,但沒法(或者很難)調用其介面,這可擴展性就大打折扣了。)

讓文件操作真的得心應手,有如神助。

另外 VimDesktop 默認配置里將左 Alt 作為特殊功能鍵使用。因為我們平時除了Alt + F4、Alt + 回車、Alt + 空格、Alt + Tab、Alt + Esc、Alt + PrtSc
等少數常用快捷鍵外,Alt
按鍵主要用於定位控制項,顯然有些大材小用了。尤其是左拇指正下方的左Alt(lalt),用於其他功能是一個好辦法,保留右Alt用於定位控制項等不頻繁的操作。

全局快捷鍵列表(字母順序) · goreliu/vimdesktop Wiki · GitHub

VimDesktop 自帶了如下軟體的插件:

BeyondCompare4

Explorer

Foobar2000

MicrosoftExcel

TotalCommander

WinMerge

WizNote

新寫一個插件也很方便,以WinMerge為例:

;plugins/WinMerge/WinMerge.ahk

WinMerge:

; 定義注釋(可選)

vim.comment("&", "下一處不同")

vim.comment("&", "上一處不同")

vim.comment("&", "第一處不同")

vim.comment("&", "最後一處不同")

; ...

; normal模式

vim.mode("normal", "WinMergeWindowClassW")

vim.map("j", "&", "WinMergeWindowClassW")

vim.map("k", "&", "WinMergeWindowClassW")

vim.map("gg", "&", "WinMergeWindowClassW")

vim.map("G", "&", "WinMergeWindowClassW")

; ...

return

&:

Send, !{down}

return

&:

Send, !{up}

return

&:

Send, !{home}

return

&:

Send, !{end}

return

; ...

只要軟體本身提供了功能對應的快捷鍵,就可以直接這樣映射過去。如果軟體提供了COM介面,或者暴露了消息介面,也可以直接操作。極端情況可以用操作菜單甚至滑鼠定位來模擬。

因為這樣軟體的主要邏輯都是和各種按鍵打交道,用 AHK 寫最合適不過。


  1. 滑鼠放在任務欄,滾動滾輪實現音量的加減

~lbutton enter::
exitapp
~WheelUp::
if (existclass("ahk_class Shell_TrayWnd")=1)
Send,{Volume_Up}
Return
~WheelDown::
if (existclass("ahk_class Shell_TrayWnd")=1)
Send,{Volume_Down}
Return
~MButton::
if (existclass("ahk_class Shell_TrayWnd")=1)
Send,{Volume_Mute}
Return

Existclass(class)
{
MouseGetPos,,,win
WinGet,winid,id,%class%
if win = %winid%
Return,1
Else
Return,0
}

2. ctrl+shift+C 實現一鍵複製文件路徑

^+c::
; null=
send ^c
sleep,200
clipboard=%clipboard% ;%null%
tooltip,%clipboard%
sleep,500
tooltip,
return

3. 將少用的caps Lock鍵映射為Enter鍵(這樣可以用左手回車)

;replace CapsLock to LeftEnter; CapsLock = Alt CapsLock
$CapsLock::Enter
LAlt Capslock::SetCapsLockState, % GetKeyState("CapsLock", "T") ? "Off" : "On"
!u::Send ^c !{tab} ^v

4. 用 Google 搜索選中的文字

!g::
Send ^c
Run http://www.google.com/search?q=%clipboard%
return

5. 按住空格不放,搭配edsf實現上下左右方向鍵,搭配cv實現backspace和del功能,搭配wr,實現home和end功能:

;
; AutoHotkey Version: 1.x
; Language: English
; Platform: Win9x/NT
; Author: cy18 & ;
; An improved script to use space as modifier
; In normal cases, if space is pressed for more than 0.1 second, it becomes a modifier, this time could be modified in the script
; If no other keys are pressed during space is pressed, a space is output when space is released
; Severial tunes are made so that the script works well when typing in fast speed
; Note that repeating space no longer works

#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.

AnyKeyPressedOtherThanSpace(mode = "P") {
keys = 1234567890-=qwertyuiop[]asdfghjkl;"zxcvbnm,./
Loop, Parse, keys
{
isDown := GetKeyState(A_LoopField, mode)
if(isDown)
return True
}
return False
}

Space Up::
space_up := true
Send, {F18}
return
Space::
if AnyKeyPressedOtherThanSpace(){
SendInput, {Blind}{Space}
Return
}
space_up := False
inputed := False
input, UserInput, L1 T0.1, {F18}
if (space_up) {
Send, {Blind}{Space}
return
}else if (StrLen(UserInput) == 1){
Send, {Space}%UserInput%
return
}
while true{
input, UserInput, L1, {F18}
if (space_up) {
if (!inputed){
Send, {Blind}{Space}
}
break
}else if (StrLen(UserInput) == 1) {
inputed := True
StringLower, UserInput, UserInput
if (UserInput == "e")
Send, {Blind}{Up}
else if (UserInput == "d")
Send, {Blind}{Down}
else if (UserInput == "s")
Send, {Blind}{Left}
else if (UserInput == "f")
Send, {Blind}{Right}
else if (UserInput == "w")
Send, {Blind}{Home}
else if (UserInput == "r")
Send, {Blind}{End}
else if (UserInput == "c")
Send, {Blind}{BS}
else if (UserInput == "v")
Send, {Blind}{DEL}
else
Send, {Blind}%UserInput%

}
}
return


貼一個自己用的搜索工具:

腳本很簡單,很容易自定義

有愛自取,自己改吧。。。

F6:打開

Ctrl+F6:打開+粘貼(到輸入框)

Ctrl+Alt+F6:複製(選中文本)+打開+粘貼(到輸入框)

鏈接: https://pan.baidu.com/s/1i569Myp 密碼: ryxt


做個狀態窗口

#NoTrayIcon
#include &
#include &
#include &
#include &
#include &
#include &
#include &
Opt("MustDeclareVars", 1)
Global $time_cnt=0,$rc=0,$cnt=0, $cnt2=0, $time_cnt=0, $sleep_cnt=0, $pause_state=0,$win_width=200,$win_height=85,$pause = 0,$title = " - play",$Paused = 1,$pause_from="",$timeout_time=300
HotKeySet("{PAUSE}", "TogglePause");HotKeySet("!{SPACE}", "TogglePause")
$rc = _RunDos("del /f /q d: esttools clawpause.cc")
$rc = _RunDos("del /f /q d: esttools clawstop.cc")
_Main()
Func _Main()
Local $button1, $button2, $button3, $button4,$button5, $buttonclose,$Input_Date, $Input_Time, $msg
GUICreate("State", $win_width, $win_height,0,0,$WS_POPUP ,$WS_EX_TOOLWINDOW+$WS_EX_TOPMOST)
$buttonclose = GUICtrlCreateButton("close", 60, 10, 40, 40, $BS_ICON)
GUICtrlSetImage(-1, "shell32.dll", 28) ;GUICtrlCreateLabel("Start Date", 10, 50, 80, 20) ;GUICtrlCreateLabel("Start Time", 10, 80, 80, 20)
$Input_Date = GUICtrlCreateInput(" " @MON "-" @MDAY "-" @YEAR, 110, 10, 80, 20)
$Input_Time = GUICtrlCreateInput(" " @HOUR ":" @MIN ":" @SEC, 110, 40, 80, 20) ;$cnt2=GUICtrlCreateLabel($time_cnt, 100, 120, 80, 20,$SS_ETCHEDFRAME ) ;$cnt=GUICtrlCreateLabel($time_cnt, 100, 120, 80, 20)
$cnt=GUICtrlCreateLabel($time_cnt, 10, 10, 40, 20)
WinSetTrans("State", "",220)
GUISetState()
WinMove("State", "", 0, 0, 200, 85)
$pause=GUICtrlCreateLabel("Play &>", 10, 30, 45, 20) ; Run the GUI until the dialog is closed
While 1
Sleep(100)
If $pause_state = 0 Then
$sleep_cnt = $sleep_cnt + 100
If $sleep_cnt = 1000 Then
$time_cnt = $time_cnt + 1
ChangeCnt()
$sleep_cnt = 0
EndIf
Else
ChangeCnt()
EndIf
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE ;MsgBox(0, "info", "Already run "$time_cnt" seconds ...",1)
ExitLoop
Case $buttonclose
$rc = _RunDos("echo rem this &>d: esttools clawstop.cc");$rc = _RunDos("del /f /q d: esttools clawpause.cc")
$rc = _RunDos("taskkill /f /im llt.exe") ;MsgBox(0, "info", "Already run "$time_cnt" seconds ...",1)
Exit
Case Else
EndSwitch
WEnd
GUIDelete()
EndFunc ;==&>_Main
Func ChangeCnt()
If $Paused Then
GUICtrlDelete($cnt)
GUICtrlDelete($cnt2)
$cnt=GUICtrlCreateLabel(" "$time_cnt, 10, 10, 40, 20 )
$cnt2=GUICtrlCreateLabel("Now " @HOUR ":" @MIN ":" @SEC, 90, 65, 100, 20 )
If $time_cnt&>$timeout_time Then
$rc = _RunDos("del /f /q d: esttools clawstop.cc")
$rc = _RunDos("del /f /q d: esttools clawpause.cc")
Exit
EndIf
Else
GUICtrlDelete($cnt2);GUICtrlDelete($cnt) ;$cnt=GUICtrlCreateLabel(" "$time_cnt, 10, 10, 40, 20 )
$cnt2=GUICtrlCreateLabel("Pause "$pause_from". Now " @HOUR ":" @MIN ":" @SEC, 10, 65, 180, 20 ) ;monitor , if process not exist , then exit
If ProcessExists("llt.exe")=0 Then ;MsgBox(0, "info", "Already run "$time_cnt" seconds ...",1)
Exit
EndIf
EndIf
EndFunc

窗口可以提示當前運行了 多久


;定時器的邏輯用法
settimer,tab,% value:=value="on"?"off":"on"


2014-10-22

使用谷歌輸入法,經常使用ctrl+shift無法調出來狀態欄(ctrl+space被我用來調用FARR),而谷歌輸入法不像搜狗那樣可以用ctrl+;一次性調用出來.於是我就新建了一個ahk文件,將ctrl+; 映射成谷歌輸入法支持的ctrl+shift+s(在設置中打開即可,這個快捷鍵太複雜,不如ctrl+;方便),從而實現了之前習慣的ctrl+;一次性打開輸入法的狀態欄,只不過打開的是谷歌,不是搜狗而已.

^;::^+S


WheelDown::AltTab

WheelUp::ShiftAltTab

#a:: Run C:/Program Files/Everything/Everything.exe

#t:: run C:/Program Files/EverEdit/EverEdit.exe

^+p::

run E:/sql/PLSQL/plsqldev.exe

Sleep, 1000

send password{enter}

return

^+x:: run C:/Program Files/Mozilla Firefox/firefox.exe

#Numpad3:: run C:/Documents and Settings/Administrator/Local Settings/Application Data/360Chrome/Chrome/Application/360chrome.exe

!q::send {Del}

#IfWinActive,編輯數據

^d::

send ^v

send {tab}

send ^v

send {tab}

send ^v

return

`::

send ^v

send {Tab}

send 人民

return

結構比較亂,沒辦法,都是自學的。。。


我說3個常用的:

  • 設置美觀醒目的Markdown標題

!1::send {home}{#}{space}----------{end}----------
!2::send {home}{#}{#}{space}---{end}---

效果就是把「標題1」格式化為「# ----------標題1----------」,把「標題2」格式化為「## ---標題2---」

  • 窗口置頂

#t::winset,AlwaysOnTop,,A

  • 快速切換Win10的虛擬桌面

使用滑鼠中間的左右功能,快速切換桌面

WheelLeft::send,^#{left}
WheelRight::send,^#{right}


可以對

大段文字

url

關鍵詞

文件

做以上發送處理.


推薦閱讀:

如何藉助Autohotkey使total commander在單雙窗口間切換?

TAG:AutoHotkey |