使用Caps(中/英)按键在虚拟机中切换输入法

133 阅读1分钟

习惯了在 macOS 上使用Caps Lock 键切换输入法,希望在虚拟机中也能延续这一习惯,避免在 Caps Lock 和 Shift 键之间来回切换

设备清单

  • mac笔记本、系统自带输入法
  • win系统(云桌面)+ PD虚拟机、系统自带微软输入法
  • karabiner elements:macOS app

问题

当宿主系统(macos)认定快捷键 ctrl + space 是切换输入法时,会被截住,导致虚拟机内的操作系统接收不到按键。

解决

宿主和虚拟机使用不同的按键组合切换输入法,然后再利用karabiner elements绑定到Caps Lock按键上。切换输入法快捷键清单:

  • mac:ctrl + option + space
  • win: ctrl + space

karabiner elements 配置如下:

{
    "description": "Caps → Hyper (hold), Ctrl+Space (tap)",
    "manipulators": [
        {
            "from": {
                "key_code": "caps_lock",
                "modifiers": { "optional": ["any"] }
            },
            "parameters": {
                "basic.to_if_alone_timeout_milliseconds": 200,
                "basic.to_if_held_down_threshold_milliseconds": 200
            },
            "to_if_alone": [
                {
                    "key_code": "spacebar",
                    "modifiers": ["left_control"]
                },
                {
                    "key_code": "spacebar",
                    "modifiers": ["left_control", "left_option"]
                }
            ],
            "to_if_held_down": [
                {
                    "key_code": "left_shift",
                    "modifiers": ["left_control", "left_option", "left_command"]
                }
            ],
            "type": "basic"
        }
    ]
}

配置的位置:

image.png

该方案会丢失锁定大写字母功能。对我无所谓,配合shift输入大写字母

mac配置

image.png

image.png

win配置

image.png

还有一个思路

对宿主的修改最小:

{
  "description": "CapsLock: Hyper when held, VM-aware tap behavior",
  "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": "f13"
        }
      ],

      "conditions": [
        {
          "type": "frontmost_application_if",
          "bundle_identifiers": [
            "^com\\.vmware\\.fusion$"
          ]
        }
      ],

      "parameters": {
        "basic.to_if_alone_timeout_milliseconds": 250
      }
    },

    {
      "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": "spacebar",
          "modifiers": [
            "left_control"
          ]
        }
      ],

      "conditions": [
        {
          "type": "frontmost_application_unless",
          "bundle_identifiers": [
            "^com\\.vmware\\.fusion$"
          ]
        }
      ],

      "parameters": {
        "basic.to_if_alone_timeout_milliseconds": 250
      }
    }
  ]
}

参考

docs.parallels.com/pdfm-ug-26/…