Skip to content

Instantly share code, notes, and snippets.

@nzooherd
Created March 3, 2024 14:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nzooherd/9e83731c70ba68f87d8c58f267ccae19 to your computer and use it in GitHub Desktop.
Save nzooherd/9e83731c70ba68f87d8c58f267ccae19 to your computer and use it in GitHub Desktop.
Mac 利用 shift 快速切换 中,英,日三种语言 Karabiner 配置
{
"description": "left shift switch input between zh-Hans and !zh-Hans, right shift switch input between ja and !ja",
"manipulators": [
{
"conditions": [
{
"input_sources": [
{
"language": "zh-Hans"
}
],
"type": "input_source_unless"
}
],
"from": {
"key_code": "left_shift"
},
"parameters": {
"basic.to_if_alone_timeout_milliseconds": 200,
"basic.to_if_held_down_threshold_milliseconds": 200
},
"to": [
{
"key_code": "left_shift",
"lazy": true
}
],
"to_if_alone": [
{
"select_input_source": {
"language": "zh-Hans"
}
}
],
"to_if_held_down": [
{
"key_code": "left_shift"
}
],
"type": "basic"
},
{
"conditions": [
{
"input_sources": [
{
"language": "zh-Hans"
}
],
"type": "input_source_if"
}
],
"from": {
"key_code": "left_shift"
},
"parameters": {
"basic.to_if_alone_timeout_milliseconds": 200,
"basic.to_if_held_down_threshold_milliseconds": 200
},
"to": [
{
"key_code": "left_shift",
"lazy": true
}
],
"to_if_alone": [
{
"select_input_source": {
"language": "en"
}
}
],
"to_if_held_down": [
{
"key_code": "left_shift"
}
],
"type": "basic"
},
{
"conditions": [
{
"input_sources": [
{
"language": "ja"
}
],
"type": "input_source_if"
}
],
"from": {
"key_code": "right_shift"
},
"to_if_alone": [
{
"select_input_source": {
"language": "en"
}
}
],
"type": "basic"
},
{
"conditions": [
{
"input_sources": [
{
"language": "ja"
}
],
"type": "input_source_unless"
}
],
"from": {
"key_code": "right_shift"
},
"to_if_alone": [
{
"select_input_source": {
"input_source_id": "com.apple.inputmethod.Kotoeri.RomajiTyping.Japanese",
"language": "ja"
}
}
],
"type": "basic"
}
]
}
@nzooherd
Copy link
Author

由于 TISSelectInputSource 的陈年 Bug, 这种方式可能切换输入法失败。

最新代码如下,利用 Option+Control+Space 的系统快捷键。左 shift 切换中文输入法,右 shift 切换日文输入法。可能需要手动调整下顺序。

{
    "description": "Use left_shift to switch input sources",
    "manipulators": [
        {
            "conditions": [
                {
                    "input_sources": [
                        {
                            "language": "en"
                        }
                    ],
                    "type": "input_source_if"
                }
            ],
            "from": {
                "key_code": "left_shift"
            },
            "parameters": {
                "basic.to_if_alone_timeout_milliseconds": 200,
                "basic.to_if_held_down_threshold_milliseconds": 200
            },
            "to": [
                {
                    "key_code": "left_shift",
                    "lazy": true
                }
            ],
            "to_if_alone": [
                {
                    "key_code": "spacebar",
                    "modifiers": [
                        "left_control",
                        "left_option"
                    ]
                },
                {
                    "key_code": "spacebar",
                    "modifiers": [
                        "left_control",
                        "left_option"
                    ]
                }
            ],
            "to_if_held_down": [
                {
                    "key_code": "left_shift"
                }
            ],
            "type": "basic"
        },
        {
            "conditions": [
                {
                    "input_sources": [
                        {
                            "language": "ja"
                        }
                    ],
                    "type": "input_source_if"
                }
            ],
            "from": {
                "key_code": "left_shift"
            },
            "parameters": {
                "basic.to_if_alone_timeout_milliseconds": 200,
                "basic.to_if_held_down_threshold_milliseconds": 200
            },
            "to": [
                {
                    "key_code": "left_shift",
                    "lazy": true
                }
            ],
            "to_if_alone": [
                {
                    "key_code": "spacebar",
                    "modifiers": [
                        "left_control",
                        "left_option"
                    ]
                }
            ],
            "to_if_held_down": [
                {
                    "key_code": "left_shift"
                }
            ],
            "type": "basic"
        },
        {
            "conditions": [
                {
                    "input_sources": [
                        {
                            "language": "zh-Hans"
                        }
                    ],
                    "type": "input_source_if"
                }
            ],
            "from": {
                "key_code": "left_shift"
            },
            "parameters": {
                "basic.to_if_alone_timeout_milliseconds": 200,
                "basic.to_if_held_down_threshold_milliseconds": 200
            },
            "to": [
                {
                    "key_code": "left_shift",
                    "lazy": true
                }
            ],
            "to_if_alone": [
                {
                    "key_code": "spacebar",
                    "modifiers": [
                        "left_control",
                        "left_option"
                    ]
                }
            ],
            "to_if_held_down": [
                {
                    "key_code": "left_shift"
                }
            ],
            "type": "basic"
        },
        {
            "conditions": [
                {
                    "input_sources": [
                        {
                            "language": "zh-Hans"
                        }
                    ],
                    "type": "input_source_if"
                }
            ],
            "from": {
                "key_code": "right_shift"
            },
            "parameters": {
                "basic.to_if_alone_timeout_milliseconds": 200,
                "basic.to_if_held_down_threshold_milliseconds": 200
            },
            "to": [
                {
                    "key_code": "left_shift",
                    "lazy": true
                }
            ],
            "to_if_alone": [
                {
                    "key_code": "spacebar",
                    "modifiers": [
                        "left_control",
                        "left_option"
                    ]
                },
                {
                    "key_code": "spacebar",
                    "modifiers": [
                        "left_control",
                        "left_option"
                    ]
                }
            ],
            "to_if_held_down": [
                {
                    "key_code": "left_shift"
                }
            ],
            "type": "basic"
        },
        {
            "conditions": [
                {
                    "input_sources": [
                        {
                            "language": "ja"
                        }
                    ],
                    "type": "input_source_if"
                }
            ],
            "from": {
                "key_code": "right_shift"
            },
            "parameters": {
                "basic.to_if_alone_timeout_milliseconds": 200,
                "basic.to_if_held_down_threshold_milliseconds": 200
            },
            "to": [
                {
                    "key_code": "left_shift",
                    "lazy": true
                }
            ],
            "to_if_alone": [
                {
                    "key_code": "spacebar",
                    "modifiers": [
                        "left_control",
                        "left_option"
                    ]
                },
                {
                    "key_code": "spacebar",
                    "modifiers": [
                        "left_control",
                        "left_option"
                    ]
                }
            ],
            "to_if_held_down": [
                {
                    "key_code": "left_shift"
                }
            ],
            "type": "basic"
        },
        {
            "conditions": [
                {
                    "input_sources": [
                        {
                            "language": "en"
                        }
                    ],
                    "type": "input_source_if"
                }
            ],
            "from": {
                "key_code": "right_shift"
            },
            "parameters": {
                "basic.to_if_alone_timeout_milliseconds": 200,
                "basic.to_if_held_down_threshold_milliseconds": 200
            },
            "to": [
                {
                    "key_code": "left_shift",
                    "lazy": true
                }
            ],
            "to_if_alone": [
                {
                    "key_code": "spacebar",
                    "modifiers": [
                        "left_control",
                        "left_option"
                    ]
                }
            ],
            "to_if_held_down": [
                {
                    "key_code": "left_shift"
                }
            ],
            "type": "basic"
        }
    ]
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment