[效率] HHKB键盘 + Autohotkey 配置秘籍

因为已经厌倦了机械键盘,又实在没法抵挡 HHKB 的颜值,入手了一枚 hhkb pro2。安全

图片描述

入手以后马上傻眼,方向键不只须要按 Fn 键才能触发,那憋屈的键位让我这用方向键与 Ctrl+C 同样多的程序猿情何以堪!好在我是程序猿,天生不怕折腾,在通过设置 DIP 开关、使用 Autohotkey 改键、设置 Win10 系统权限等一系列的折腾以后,终于能够舒服的使用这款 HHKB 写代码了,效率更超以前的机械键盘。编辑器

设置 DIP 开关

SW1 on、SW2 off = Lite ext 模式,既 ◇ 键为 Win 键。
SW3 on = Delete 键改成退格键。
SW4 on = 左侧 ◇ 键为 Fn 键。
SW5 off = 不交换 ◇ 与 Alt 键。
SW6 on = 启用唤醒功能。测试

使用 Autohotkey 改键

首先要解决方向键问题。我并非 Emacs/Vim 党,想来想去仍是把“上下左右”的快捷键设置成 Ctrl + I、K、J、L 比较直观。另外,编代码时跳到行首、行尾的操做也不少,因此能够再加上 Ctrl + H 跳到行首,Ctrl + ' 跳到行尾的快捷键。脚本也很简单:优化

^j::Send,{Left}
^l::Send,{Right}
^i::Send,{Up}
^k::Send,{Down}
^h::Send,{Home}
^'::Send,{End}

可是,仅仅这样并无比原来方便,既然进入了双手不离开主键盘区的领域,就要尽量减小使用鼠标才能提升效率,毕竟如今要实现按方向键已经必须使用两只手了。编代码选中变量名的操做不少,咱们已经实现了 Ctrl + I、K、J、L 上下左右移动光标,若是能实现 Ctrl + ◇ + I、K、J、L 上下左右选中文本就很是方便并且直观了!观察一下 HHKB 的键盘,正好 ◇ + I、K、J、L 等价于 PrintScreen、Home、小键盘的除号、PageUp 键,因此就再增长以下脚本代码:spa

^PrintScreen up::Send,{RShift down}{Up}{RShift up}
^Home up::Send,{RShift down}{Down}{RShift up}
^NumpadDiv up::Send,+{Left}
^PgUp up::Send,{RShift down}{Right}{RShift up}

注意在每一个快捷键后面都加上了 “up”。这是由于在测试时发现,若是 Ctrl + ◇ + J 按住的话,也就是但愿光标以最快速度往左侧选中文本的时候,每选中五、6个字母,选中的字母就会被一个 “/” 字母替换掉!也就是原本应该连续输出 Shift + Left,却偶尔直接输出了 “/”。而快捷键后面加上 “up” 的意思是不容许按住,只容许一下一下按快捷键。这样虽然不会出错了,可是这一下一下按效率实在过低了。通过反复尝试,我找到一个秘技:先使用 “NumpadDiv::CtrlBreak” 和 “PgUp::CtrlBreak” 把要输出的快捷键改成不会实际输出字符的“CtrlBreak”键,就不怕键冲突了。实际脚本这个样子:操作系统

NumpadDiv::CtrlBreak
PgUp::CtrlBreak

^NumpadMult up::Send,{RShift down}{Home}{RShift up}
^NumpadDiv::Send,+{Left}
^Home up::Send,{RShift down}{Down}{RShift up}
^PgUp::Send,{RShift down}{Right}{RShift up}
^PrintScreen up::Send,{RShift down}{Up}{RShift up}
^Right up::Send,{RShift down}{End}{RShift up}
^NumpadSub up::Send,{RControl down}{Left}{RControl up}{RControl down}{RShift down}{Right}{RControl up}{RShift up} ;select whole word left to right
^End up::Send,{RControl down}{RShift down}{Left}{RControl up}{RShift up} ;select whole word left
^PgDn up::Send,{RControl down}{RShift down}{Right}{RControl up}{RShift up} ;select whole word right
^NumpadAdd up::Send,{Home}+{End}

上面的脚本还同时实现了 Ctrl + M 选中单词,Ctrl + N 选中行,Ctrl + < 向左按单词扩选,Ctrl + > 向右按单词扩选。最棒的仍是能够容许按住 Ctrl + ◇ + J 和 Ctrl + ◇ + L 来快速扩选了,代价是牺牲了小键盘除号和PageUp键,不过能够接受。rest

另外像把变量首字母由大写改成小写这样的功能,虽然不是很经常使用,但也能有效提高效率,我把快捷键设置为 Ctrl + 反引号,实现起来稍稍有点复杂但也不难。使用一段时间,作了些优化和微调,最终的Autohotkey脚本:code

NumpadDiv::CtrlBreak
PgUp::CtrlBreak

^j::Send,{Left}
^l::Send,{Right}
^i::Send,{Up}
^k::Send,{Down}
^h::Send,{Home}
^'::Send,{End}

^NumpadMult up::Send,{RShift down}{Home}{RShift up}
^NumpadDiv::Send,+{Left}
^Home up::Send,{RShift down}{Down}{RShift up}
^PgUp::Send,{RShift down}{Right}{RShift up}
^PrintScreen up::Send,{RShift down}{Up}{RShift up}
^Right up::Send,{RShift down}{End}{RShift up}
^NumpadSub up::Send,{RControl down}{Left}{RControl up}{RControl down}{RShift down}{Right}{RControl up}{RShift up} ;select whole word left to right
^End up::Send,{RControl down}{RShift down}{Left}{RControl up}{RShift up} ;select whole word left
^PgDn up::Send,{RControl down}{RShift down}{Right}{RControl up}{RShift up} ;select whole word right
^NumpadAdd up::Send,{Home}+{End}

RWin & '::Send,{RWin down}{RControl down}{Right}{RWin up}{RControl up}
RWin & `;::Send,{RWin down}{RControl down}{Left}{RWin up}{RControl up}

+Esc::Send,{RAlt down}{Left}{RAlt up}
+Tab::Send,{RAlt down}{Right}{RAlt up}

; Ctrl + ` set firt char to lower
^`::
    clipBak := ClipboardAll ; bak clipboard
    Clipboard := "" ;clear clipboard
    Send,{RControl down}{Left}{RControl up}{RShift down}{Right}{RShift up}{RControl down}c{RControl up} ;copy first char to clipboard
    ClipWait, 1 ;wait clip complete
    ; convert firt char in clipboard to lower
    selText := Clipboard
    ;MsgBox % selText
    StringLower, selText, selText
    ; set lower char to clipboard and paste it to replace in place
    Clipboard := selText
    Send, ^v
    Sleep, 100 ;prevent restore clipBak too early
    Clipboard := clipBak ; restore clipboard
    Send, {RControl down}{Right}{RControl up}
return

;Ignore these shortkey
^1::return
^2::return
^3::return
^4::return
^5::return
^6::return
^7::return
^8::return
^9::return
^0::return
^-::return
^=::return
^\::return
^Left::return

设置 Win10 权限

到目前为止彷佛一切都很完美,可是打开 Visual Studio,忽然发如今 VS 里面刚刚设置的全部快捷键全!失!效!!一开始还觉得是 VS 把全局快捷键给屏蔽了,想找找能不能经过 VS 里面的设置不屏蔽全局快捷键,结果无功而返,感受怕是解决不了了。后来仍是在靠谱的 Stackoverflow 里面找到了答案。原来是由于 VS 运行于管理员权限,而 Autohotkey 运行于普通用户权限。解决方法就是在 AutoHotkeyU64.exe(若是是64位操做系统的话)右击,选“属性”,在“兼容性”选项卡里,勾选“以管理员身份运行此程序”。图片

终于解决了 VS 快捷键失效的问题,可是立刻又发现以管理员身份运行 Autohotkey 会形成它不能开机自动启动。解决方法是禁用 UAC。禁用 UAC 的方法是:Win+R,输入gpedit.msc,运行打开“本地组策略编辑器”,计算机配置->Windows设置->安全设置->本地策略->安全选项->以管理员批准模式运行全部管理员,改成"已禁用"便可。ip

相关文章
相关标签/搜索