使用AutoHotKey优化capslock功能
写代码总是被括号和引号所困扰。打完括号里的内容,想要移出光标到括号外,需要去点击右方向键,有点慢。现在使用autokey软件把几乎没用的capslock改为右方向键,用起来爽多了。同时结合hjkl来实现Vim的方向键功能。
首先安装autohotkey软件;
然后建立一个脚本文件,后缀名为.ahk;
写入以下代码实现:
;=====================================================================o ; CapsLock Initializer ;| ;---------------------------------------------------------------------o SetCapsLockState, AlwaysOff ;| ;---------------------------------------------------------------------o ;=====================================================================o ; CapsLock singlekey-right ;| ;---------------------------------------------------------------------o CapsLock::Send, {Right} ;| ;---------------------------------------------------------------------o ;=====================================================================o ; CapsLock singlekey-left ;| ;---------------------------------------------------------------------o CapsLock & shift:: ;| 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 ;=====================================================================o ; CapsLock singlekey-left ;| ;---------------------------------------------------------------------o shift & CapsLock:: ;| 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 ;=====================================================================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
该配置实现了capslock的这几个作用:
1、单击热键实现光标右移一位;
2、+shift实现光标左移一位;
3、+hjkl实现各个方向的移位;
4、+i和+o分别实现home和end的功能;