karabiner-elements

三月 12, 2022 [macOS, keymapping] #macOS #keymapping

karabiner-elements

使用命令行/vim/emacs等键盘操作比较多的用户,有一点感触就是:小拇指很容易累。本人起初不喜欢修改键盘映射,主要原因是定制化比较多的系统,在团队合作时互相操作会不方便,无论是自己偶尔在别人电脑上使用或者别人在自己的电脑上使用,都会不习惯。ORZ最后因为vim经常使用ctrl键,左小拇指开始疼痛,了解了一些腕管综合征知识(xahlee.info) 囧,决定把几个常用的键映射一下。最近在使用的系统是macOS,这里就先记录一下使用到karabiner-elements的键盘映射。 这里尽量不修改键盘原来功能,而是将不常用的键直接映射为经常使用的功能。

Simple Modifications

尽量少的修改键盘映射,让偶尔同事使用电脑操作时可以正常使用,这里只进行了right_command > right_control的映射,解决使用ctrl键的问题,这样常用的command和ctrl键都使用大拇指操作,大大减少了小拇指的压力 ..
image

complex modifications

  1. 需要解决的是经常需要enter键,对有小拇指的压力压力也比较明显,因此同时修改了enter的映射,如果只按压right_control,那么会映射为return_or_enter(这个真的挺合理,毕竟一般control键是和别的键搭配使用的,单独按压不影响原来的功能,赞)。
  2. 如果只按压left_command,那么会映射为escape.
  3. 另一个就是经常需要ctrl+p 进行选择上一个的功能,比如翻看命令行的历史记录,vim/emacs补全时的上下选择,使用了command + h/j/k/l。
    image
  4. 最后一个向前删除还没有找到特别合适的映射。

keymapping for linux

alternative of karabiner-elements

  1. Actiona

  2. Input Remapper

  3. Repeat

  4. xcape

  5. xmodmap

  6. kmonad

    Wayland and TTY compatible. It's awesome!!

记录一下映射文件的rule

~/.config/karabiner/assets/complex_modifications/xxx.json

{
  "title": "Personal rules (@kbdluv) (rev 2)",
  "rules": [
    {
      "description": "Post Escape if Command_L is pressed alone.",
      "manipulators": [
        {
          "type": "basic",
          "from": {
            "key_code": "left_command",
            "modifiers": {
              "optional": [
                "any"
              ]
            }
          },
          "to": [
            {
              "key_code": "left_command",
              "lazy": true
            }
          ],
          "to_if_alone": [
            {
              "key_code": "escape"
            }
          ]
        }
      ]
    },
    {
      "description": "Post Escape if Command_R is pressed alone.",
      "manipulators": [
        {
          "type": "basic",
          "from": {
            "key_code": "right_command",
            "modifiers": {
              "optional": [
                "any"
              ]
            }
          },
          "to": [
            {
              "key_code": "right_command",
              "lazy": true
            }
          ],
          "to_if_alone": [
            {
              "key_code": "escape"
            }
          ]
        }
      ]
    },
    {
      "description": "Post left_control if Spacebar is held down.",
      "manipulators": [
        {
          "type": "basic",
          "from": {
            "key_code": "spacebar",
            "modifiers": {
              "optional": [
                "any"
              ]
            }
          },
          "to_if_alone": [
            {
              "key_code": "spacebar"
            }
          ],
          "to": [
            {
              "key_code": "left_control",
              "lazy": true
            }
          ]
        }
      ]
    },
    {
      "description": "Post grave_accent_and_tilde if Caps Lock is pressed alone, left_shift if held down. (rev 2)",
      "manipulators": [
        {
          "type": "basic",
          "from": {
            "key_code": "caps_lock",
            "modifiers": {
              "optional": [
                "any"
              ]
            }
          },
          "to": [
            {
              "key_code": "left_shift",
              "lazy": true
            }
          ],
          "to_if_alone": [
            {
              "key_code": "grave_accent_and_tilde"
            }
          ]
        }
      ]
    },
    {
      "description": "Post return_or_enter if Enter is pressed alone, right_shift if held down. (rev 2)",
      "manipulators": [
        {
          "type": "basic",
          "from": {
            "key_code": "return_or_enter",
            "modifiers": {
              "optional": [
                "any"
              ]
            }
          },
          "to": [
            {
              "key_code": "right_shift",
              "lazy": true
            }
          ],
          "to_if_alone": [
            {
              "key_code": "return_or_enter"
            }
          ]
        }
      ]
    }
  ]
}
{
  "title": "Change control key",
  "rules": [
    {
      "description": "Post escape if left_control is pressed alone.",
      "manipulators": [
        {
          "type": "basic",
          "from": {
            "key_code": "left_control",
            "modifiers": {
              "optional": [
                "any"
              ]
            }
          },
          "to": [
            {
              "key_code": "left_control"
            }
          ],
          "to_if_alone": [
            {
              "key_code": "escape"
            }
          ]
        }
      ]
    },
    {
      "description": "Post caps_lock if left_control is pressed alone.",
      "manipulators": [
        {
          "type": "basic",
          "from": {
            "key_code": "left_control",
            "modifiers": {
              "optional": [
                "any"
              ]
            }
          },
          "to": [
            {
              "key_code": "left_control"
            }
          ],
          "to_if_alone": [
            {
              "key_code": "caps_lock"
            }
          ]
        }
      ]
    },
    {
      "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"
            }
          ]
        }
      ]
    }
  ]
}
{
  "title": "command + h/j/k/l/u/i to arrow keys and home end",
  "rules": [
    {
      "description": "Change Command + h/j/k/l to Arrows",
      "manipulators": [
        {
          "type": "basic",
          "from": {
            "key_code": "h",
            "modifiers": {
              "mandatory": [
                "command"
              ],
              "optional": [
                "any"
              ]
            }
          },
          "to": [
            {
              "key_code": "left_arrow"
            }
          ]
        },
        {
          "type": "basic",
          "from": {
            "key_code": "j",
            "modifiers": {
              "mandatory": [
                "command"
              ],
              "optional": [
                "any"
              ]
            }
          },
          "to": [
            {
              "key_code": "down_arrow"
            }
          ]
        },
        {
          "type": "basic",
          "from": {
            "key_code": "k",
            "modifiers": {
              "mandatory": [
                "command"
              ],
              "optional": [
                "any"
              ]
            }
          },
          "to": [
            {
              "key_code": "up_arrow"
            }
          ]
        },
        {
          "type": "basic",
          "from": {
            "key_code": "l",
            "modifiers": {
              "mandatory": [
                "command"
              ],
              "optional": [
                "any"
              ]
            }
          },
          "to": [
            {
              "key_code": "right_arrow"
            }
          ]
        }
      ]
    },
    {
      "description": "Change Command + u/i to home/end",
      "manipulators": [
        {
          "type": "basic",
          "from": {
            "key_code": "u",
            "modifiers": {
              "mandatory": [
                "command"
              ],
              "optional": [
                "any"
              ]
            }
          },
          "to": [
            {
              "key_code": "home"
            }
          ]
        },
        {
          "type": "basic",
          "from": {
            "key_code": "i",
            "modifiers": {
              "mandatory": [
                "command"
              ],
              "optional": [
                "any"
              ]
            }
          },
          "to": [
            {
              "key_code": "end"
            }
          ]
        }
       
      ]
    }
  ]
}