macOS 键盘 fn 与 左ctrl 功能互换

习惯了 键盘的左下角 是 ctrl, 为了顺手些, 把mac的键盘调整一下.

键盘按键调整

键位调整: 改造之前的样子

键位调整: 撬开键帽

键位调整: 改造好之后

按键映射

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
chunlideMacBook-Pro:~ chunli$ cat ~/.key_remap.sh
#/bin/bash

FROM="\"HIDKeyboardModifierMappingSrc\""
TO="\"HIDKeyboardModifierMappingDst\""

KeyboardLeftControl="0x7000000E0"
KeyboardLeftFn="1095216660483"

hidutil property --set "{\"UserKeyMapping\":[
{$FROM: $KeyboardLeftControl, $TO: $KeyboardLeftFn},
{$FROM: $KeyboardLeftFn, $TO: $KeyboardLeftControl}
]}"


# key id 参考
# https://developer.apple.com/library/archive/technotes/tn2450/_index.html

# 参考
# https://apple.stackexchange.com/questions/340607/what-is-the-hex-id-for-fn-key

chunlideMacBook-Pro:~ chunli$

按键映射 开机自启

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
chunlideMacBook-Pro:~ chunli$ cat   ~/Library/LaunchAgents/com.remapkeys.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.remapkeys</string>
<key>ProgramArguments</key>
<array>
<string>zsh</string>
<string>-c</string>
<string>/Users/chunli/.key_remap.sh</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
chunlideMacBook-Pro:~ chunli$

添加开机自启服务项

1
2
3
4
chunlideMacBook-Pro:~ chunli$ launchctl load -w ~/Library/LaunchAgents/com.remapkeys.plist
chunlideMacBook-Pro:~ chunli$ launchctl list | grep -i remap
- 0 com.remapkeys
chunlideMacBook-Pro:~ chunli$

重启验证

reboot

测试

  1. 新的FN + F1/F2/F3/F4/F5/F6/F7/F8/F9
  2. 浏览器 上下翻页测试: 新的FN + up/down
  3. 命令行 上下翻屏测试: 新的fn+shift+up/down
  4. MSTSC remote 远程桌面, FN 与 ctrl 测试

完美!!!