macos键盘映射修改

时间:2024-03-09 18:13:51

在windows下,我使用AutoHotkey (AHK)进行键盘映射,AHK不支持macos,所以重新选了一款软件,这款软件是Karabiner-Elements

要把键位映射成什么样子?

如下图:

映射图

这样基本就可以实现在编辑东西的时候不需要使用鼠标了。

配置Karabiner-Elements

vi方式的上下左右使用官网带的(Add rule->import from internet)就可以了。其余的我自己创造一下。

进入目录~/.config/karabiner/assets/complex_modifications 中,新建一个my.json文件,写入如下内容:

{
    "title": "my_key_map",
    "rules": [
      {
        "description": "my_key_map",
        "manipulators": [
          {
            "type": "basic",
            "from": {  
              "key_code": "u",
              "modifiers": {
                "mandatory": [ "command" ], 
                "optional": [ "any" ]
              }
            },
            "to": [
              {
                "key_code": "left_arrow",
                "modifiers": [
                    "command"
                ]
              }
            ]
          },
          {
            "type": "basic",
            "from": {  
              "key_code": "y",
              "modifiers": {
                "mandatory": [ "command" ], 
                "optional": [ "any" ]
              }
            },
            "to": [
              {
                "key_code": "left_arrow",
                "modifiers": [
                    "command",
                    "shift"
                ]
              }
            ]
          },
          {
            "type": "basic",
            "from": {  
              "key_code": "i",
              "modifiers": {
                "mandatory": [ "command" ], 
                "optional": [ "any" ]
              }
            },
            "to": [
              {
                "key_code": "right_arrow",
                "modifiers": [
                    "command"
                ]
              }
            ]
          },
          {
            "type": "basic",
            "from": {  
              "key_code": "o",
              "modifiers": {
                "mandatory": [ "command" ], 
                "optional": [ "any" ]
              }
            },
            "to": [
              {
                "key_code": "right_arrow",
                "modifiers": [
                    "command",
                    "shift"
                ]
              }
            ]
          },
          {
            "type": "basic",
            "from": {  
              "key_code": "comma",
              "modifiers": {
                "mandatory": [ "command" ], 
                "optional": [ "any" ]
              }
            },
            "to": [
              {
                "key_code": "left_arrow",
                "modifiers": [
                    "shift"
                ]
              }
            ]
          },
          {
            "type": "basic",
            "from": {  
              "key_code": "period",
              "modifiers": {
                "mandatory": [ "command" ], 
                "optional": [ "any" ]
              }
            },
            "to": [
              {
                "key_code": "right_arrow",
                "modifiers": [
                    "shift"
                ]
              }
            ]
          },
          {
            "type": "basic",
            "from": {  
              "key_code": "d",
              "modifiers": {
                "mandatory": [ "command" ], 
                "optional": [ "any" ]
              }
            },
            "to": [
              {
                "key_code": "delete_forward"
              }
            ]
          }
        ]
      }
    ]
  }

然后在Add rule时就可以看到该配置项,Enable它即可。

配置文件说明

其实不需要太多说明,根据已有的配置文件猜一猜,改一改就可以了。

备注

各个键对应的英文名是什么?

可以在Karabiner-Elements的Simple modifications中看到。