macOS Sierra 中可以使用Karabiner-Elements 进行按键映射:
我的目的是单独按下F11,就相当于按下end.
但是fn+F11 ,就无法减少音量了,很奇怪.
所以采用脚本的方法实现:
{ "description": "Post end when F11 is pressed alone.post home when is held util 1 second", "manipulators": [ { "from": { "key_code": "f11", "modifiers": { } }, "to": [ { } ], "to_if_held_down": [ { "key_code": "home" } ], "parameters": { "basic.to_delayed_action_delay_milliseconds": 2500, "basic.to_if_held_down_threshold_milliseconds": 1000 }, "to_if_alone": [ { "key_code": "end" } ], "type": "basic" } ] }
上述脚本的功能:
1,单独按下F11,相当于end;
2,单独按下F11,不松开,触发home;
多长时间算作不松开,由to_if_held_down_threshold_milliseconds 指定;
3,不影响fn+F11,依然可以减少音量
详解:
参考:
附录:我的Karabiner-Elements 配置
本地配置文件:
/Users/whuanghkl/.config/karabiner/assets/complex_modifications{ "title": "Change control key", "rules": [ { "description": "Post F17 if right_command is pressed alone.单独按下right_command触发F17", "manipulators": [ { "type": "basic", "from": { "key_code": "right_command", "modifiers": { "optional": [ "any" ] } }, "to": [ { "key_code": "right_command" } ], "to_if_alone": [ { "key_code": "f17" } ] } ] }, { "description": "Post F16 if right_option is pressed alone.单独按下right_option/alt触发F16", "manipulators": [ { "type": "basic", "from": { "key_code": "right_option", "modifiers": { "optional": [ "any" ] } }, "to": [ { "key_code": "right_option" } ], "to_if_alone": [ { "key_code": "f16" } ] } ] }, { "description": "Post F18 if fn is pressed alone.单独按下 fn 触发F18", "manipulators": [ { "type": "basic", "from": { "key_code": "fn", "modifiers": { "optional": [ "any" ] } }, "to": [ { "key_code": "fn" } ], "to_if_alone": [ { "key_code": "f18" } ] } ] }, { "description": "Post COMMAND_L+` if left_command is pressed alone.单独按下left_command触发IDEA 回到句尾", "manipulators": [ { "type": "basic", "from": { "key_code": "left_command", "modifiers": { "optional": [ "any" ] } }, "to": [ { "key_code": "left_command" } ], "to_if_alone": [ { "key_code": "grave_accent_and_tilde", "modifiers": [ "left_command" ] } ] } ] }, { "description": "Post TAB, ModifierFlag::COMMAND_L if left_control is pressed alone.单独按下left_control触发切换窗口", "manipulators": [ { "type": "basic", "from": { "key_code": "left_control", "modifiers": { "optional": [ "any" ] } }, "to": [ { "key_code": "left_control" } ], "to_if_alone": [ { "key_code": "tab", "modifiers": [ "left_command" ] } ] } ] }, { "description": "Post T, ModifierFlag::COMMAND_L if left_option is pressed alone.单独按下 left_option 触发IDEA 接口路径查找", "manipulators": [ { "type": "basic", "from": { "key_code": "left_option", "modifiers": { "optional": [ "any" ] } }, "to": [ { "key_code": "left_option" } ], "to_if_alone": [ { "key_code": "t", "modifiers": [ "left_command" ] } ] } ] }, { "description": "Post right_command when return_or_enter is hold.", "manipulators": [ { "from": { "key_code": "return_or_enter", "modifiers": { } }, "to": [ { "key_code": "right_command" } ], "to_if_alone": [ { "key_code": "return_or_enter" } ], "type": "basic" } ] }, { "description": "Post end when F11 is pressed alone.post home when is held util 1 second", "manipulators": [ { "from": { "key_code": "f11", "modifiers": { } }, "to": [ { } ], "to_if_held_down": [ { "key_code": "home" } ], "parameters": { "basic.to_delayed_action_delay_milliseconds": 2500, "basic.to_if_held_down_threshold_milliseconds": 1000 }, "to_if_alone": [ { "key_code": "end" } ], "type": "basic" } ] }, { "description": "Post right_command when space is hold.按下 space 并且hold时触发 right_command", "manipulators": [ { "from": { "key_code": "spacebar", "modifiers": { } }, "to": [ { "key_code": "right_command" } ], "to_if_alone": [ { "key_code": "spacebar" } ], "type": "basic" } ] }, { "description": "Change caps_lock key to command+control+option+shift. (Post escape key when pressed alone)", "manipulators": [ { "type": "basic", "from": { "key_code": "caps_lock", "modifiers": { "optional": [ "any" ] } }, "to": [ { "key_code": "left_shift", "modifiers": [ "left_command", "left_control", "left_option" ] } ], "to_if_alone": [ { "key_code": "escape" } ] } ] }, { "description": "Change shift_r key to B+COMMAND_L+CONTROL_L. (IDEA build)", "manipulators": [ { "type": "basic", "from": { "key_code": "right_shift", "modifiers": { "optional": [ "any" ] } }, "to": [ { "key_code": "right_shift" } ], "to_if_alone": [ { "key_code": "b", "modifiers": [ "left_command", "left_control" ] } ] } ] }, { "description": "Post COMMAND_L+OPTION_L+I if esc(F13) is pressed alone,打开浏览器调试", "manipulators": [ { "type": "basic", "from": { "key_code": "f13", "modifiers": { "optional": [ "any" ] } }, "to": [ { "key_code": "f13" } ], "to_if_alone": [ { "key_code": "i", "modifiers": [ "left_command", "left_option" ] } ] } ] }, { "description": "Post option_L+T(svn update) right_option x2(双击);post left_shift+10(IDEA run) when is pressed alone", "manipulators": [ { "type": "basic", "from": { "key_code": "right_option", "modifiers": { "optional": [ "any" ] } }, "to": [ { "key_code": "t", "modifiers": [ "left_option" ] } ], "conditions": [ { "type": "variable_if", "name": "right_option pressed", "value": 1 } ] }, { "type": "basic", "from": { "key_code": "right_option", "modifiers": { "optional": [ "any" ] } }, "parameters": { "basic.to_delayed_action_delay_milliseconds": 1000 }, "to": [ { "set_variable": { "name": "right_option pressed", "value": 1 } }, { "key_code": "right_option" } ], "to_delayed_action": { "to_if_invoked": [ { "set_variable": { "name": "right_option pressed", "value": 0 } }, { "key_code": "f10", "modifiers": [ "left_shift" ] } ], "to_if_canceled": [ { "set_variable": { "name": "right_option pressed", "value": 0 } } ] } } ] }, { "description": "Post return_or_enter if right_control is pressed alone.", "manipulators": [ { "type": "basic", "from": { "key_code": "right_control", "modifiers": { "optional": [ "any" ] } }, "to": [ { "key_code": "right_control" } ], "to_if_alone": [ { "key_code": "return_or_enter" } ] } ] } ]}
mac 快捷键