@
qgy18 Karabiner 自带的切换输入法的功能有点 bug,有时候切换到中文输入法后输出的还是英文。因此我采用了另外一种实现:在系统设置中更改默认切换输入法快捷键 ⌘+Space 为不存在的按键 F18,然后用 Karabiner 映射单按 shift 为 F18 来实现切换输入法。
下面是我的实现(有简化过,因为我的需求更复杂),供参考:
<item>
<name>Shift Keys to Switch Input Method</name>
<appendix>Shift keys to F18 on OS X</appendix>
<appendix>(Works well with setting F18 to switch input method in System Preferences)</appendix>
<identifier>private.shifts_to_switch_input_method</identifier>
<modifier_not>
ModifierFlag::COMMAND_L, ModifierFlag::COMMAND_R,
ModifierFlag::OPTION_L, ModifierFlag::OPTION_R,
ModifierFlag::CONTROL_L, ModifierFlag::CONTROL_R
</modifier_not>
<block>
<!-- SHIFT_L -->
<modifier_not>ModifierFlag::SHIFT_R</modifier_not>
<autogen>
__KeyOverlaidModifier__
<!-- from -->
KeyCode::SHIFT_L,
<!-- hold -->
KeyCode::SHIFT_L,
<!-- tap -->
KeyCode::F18
</autogen>
</block>
<block>
<!-- SHIFT_R -->
<modifier_not>ModifierFlag::SHIFT_L</modifier_not>
<autogen>
__KeyOverlaidModifier__
<!-- from -->
KeyCode::SHIFT_R,
<!-- hold -->
KeyCode::SHIFT_R,
<!-- tap -->
KeyCode::F18
</autogen>
</block>
</item>
<!-- input source definition -->
<inputsourcedef>
<!-- english input method -->
<name>ENGLISH</name>
<languagecode>en</languagecode>
</inputsourcedef>
<item>
<name>Command Keys Remappings</name>
<appendix>Tap Command Keys to Change Input Method</appendix>
<appendix>(Command_L to English)</appendix>
<appendix>(Command_R to Chinese)</appendix>
<appendix>(On OS X, use F18 to change input method)</appendix>
<identifier>private.commands_remappings</identifier>
<modifier_not>
ModifierFlag::OPTION_L, ModifierFlag::OPTION_R,
ModifierFlag::SHIFT_L, ModifierFlag::SHIFT_R,
ModifierFlag::CONTROL_L, ModifierFlag::CONTROL_R
</modifier_not>
<block>
<!-- Current is not English -->
<inputsource_not>ENGLISH</inputsource_not>
<!-- Command_L => F18 (tap) / Command_L (hold) -->
<modifier_not>ModifierFlag::COMMAND_R</modifier_not>
<autogen>
__KeyOverlaidModifier__
<!-- from -->
KeyCode::COMMAND_L,
<!-- hold -->
KeyCode::VK_LAZY_COMMAND_L,
<!-- tap -->
KeyCode::F18
</autogen>
</block>
<block>
<!-- Current is English -->
<inputsource_only>ENGLISH</inputsource_only>
<!-- Command_R => F18 (tap) / Command_R (hold) -->
<modifier_not>ModifierFlag::COMMAND_L</modifier_not>
<autogen>
__KeyOverlaidModifier__
<!-- from -->
KeyCode::COMMAND_R,
<!-- hold -->
KeyCode::VK_LAZY_COMMAND_R,
<!-- tap -->
KeyCode::F18
</autogen>
</block>
</item>