MacOS更改鍵盤設定:Karabiner-Elements

前言

Ya-Liang Allen Chang
6 min readNov 16, 2019

由於我一直是Linux的支持者,基本上很少用mac,只覺得mac C/P值不高,跟其他筆電接口不相容有點反感。不過這次公司配了MacBook Pro,也沒有其他桌機,以後工作都得要靠它,只好開始研究一下了。

想當然爾,我的原則是:

一台電腦,沒有改鍵盤設定,怎麼能工作呢!!

(除了鍵盤設定其實還有command line跟環境的設定,有空再跟大家分享)

於是繼先前研究LinuxWindows改鍵盤設定之後,這次來談談macOS的Karabiner-Elements吧!

Karabiner-Elements星星高達9.4k,相當驚人(對比Windows的AutoHotKey只有0.7k左右)

安裝

AutoHotKey一樣,Karabiner-Elements的安裝非常簡單,只要到官網下載安裝檔執行就好了,Document也寫的相當清楚,沒遇到什麼問題。

功能

有人說Karabiner-Elements大概就等於Mac的AutoHotKey,功能相當強大,從基本的改mapping(如ctrl跟capslock對調)到使用modifier的複雜功能(比如把capslock+h當成是左方向鍵)都可以做到。

以下是官網的Core feature介紹:

  • Simple Modifications: Map normal keys to arbitrary key functions.
  • Complex Modifications: Map keys by complex rules. e.g., key to modifiers, modifiers+key to key, send key event if pressed alone, etc.
  • Function Keys: Map function keys to arbitrary key functions.
  • Devices: Apply modifications to specified keyboards only.
  • Profiles: Support the creation of multiple profiles that the user can switch between.
  • Modifier Flag Sync: Synchronize modifier flags across all connected keyboards.
  • Secure Keyboard Entry Support: Work well on Secure Keyboard Entry environment such as a password prompt, terminal with Secure Keyboard Entry, etc.

而目前的限制是不能改eject key跟fn key

設定

官網有清楚的設定教學,只要照著做就可以了。如果只是要改mapping的話就用Simple Modifications:

https://pqrs.org/osx/karabiner/document.html

不過如果要比較進階的Modifier設定,就得到Complex Modification去import rules:

https://pqrs.org/osx/karabiner/document.html

這些rule是用JSON寫的,大概會長這樣:

"rules": [
{
"description": "CapsLock to Hyper/Escape",
"manipulators": [
{
"from": {
"key_code": "caps_lock",
"modifiers": {
"optional": [
"any"
]
}
},
"to": [
{
"key_code": "right_shift",
"modifiers": [
"right_command",
"right_control",
"right_option"
]
}
],
"to_if_alone": [
{
"key_code": "escape"
}
],
"type": "basic"
}
]
},
(...)

有點複雜,但基本上就是用改變原本key_code跟modifiers的功能,對應到新的按鍵,也可以直接呼叫command。

官網上面有各種tempalte rule,有興趣可以研究看看。

不過我已經用習慣我之前的鍵盤設定,如果換不同的電腦工作還要想新的鍵盤設定,也是挺麻煩的。官網的tempalte上找不到類似的設定,要重新寫JSON檔也很耗費力氣,還好我在GitHub找到了很像的Make CapsLock Great Again!

只要照著說明,把karabiner://karabiner/assets/complex_modifications/import?url=https://raw.githubusercontent.com/Vonng/Capslock/master/mac/capslock.json 貼到網址就可以import。

他的設定長這樣:

https://github.com/Vonng/Capslock

很齊全、而且跟我原本的設定很像!有種找到知音的感覺~

import後的JSON檔預設會在$HOME/.config/karabiner/assets/complex_modifications 底下,只要改一下config,調整PgUp/PgDn/Enter的位置,重新import,就跟我原本的設定一樣了。

大家也一起來收服鍵盤設定吧!

--

--