切换到特定输入源

Nik*_*kem 23 keyboard-shortcuts keyboard-layout macos

在 Mac OS X 中,有一个键盘快捷键可以激活的输入源之间切换。

替代文字

是否可以切换特定语言?因此,如果您有 3 种输入法,则可以有 3 个快捷方式:Ctrl-1英语、Ctrl-2西班牙语和Ctrl-3俄语。

Asm*_*mus 12

鉴于您知道要切换到的键盘布局的名称,我在 AppleScript 中想出了一个更好的解决方案。创建一个这样的函数:

on changeKeyboardLayout(layoutName)
 tell application "System Events" to tell process "SystemUIServer"
   tell (1st menu bar item of menu bar 1 whose description is "text input") to {click, click (menu 1's menu item layoutName)}
 end tell
end changeKeyboardLayout
Run Code Online (Sandbox Code Playgroud)

然后调用它

 changeKeyboardLayout("English")
 changeKeyboardLayout("German")
Run Code Online (Sandbox Code Playgroud)

请注意,键盘布局的名称是本地化的,即在德国系统上,上述示例需要调用“Englisch”和“Deutsch”。

  • 这多年来一直完美运行,但对于 Catalina,似乎不再可以在菜单栏中访问“输入文本” (2认同)

Dan*_*eck 7

我向您展示最丑陋的“解决方案”:

  • 系统偏好设置»通用访问中启用对辅助设备的支持,
  • 并在System Preferences » Language and Text的菜单栏中显示 Input Sources 菜单。
  • 确保在System Preferences » Keyboard » Keyboard Shortcuts » Keyboard & Text Input 中Ctrl-F8Move focus to status menus定义了快捷方式
  • 确保输入源菜单是最左边的菜单项,可以通过按住拖动来移动Cmd

使用AppleScript Editor和编写三个脚本,每个脚本的代码如下:

tell application "System Events"
    key code 100 using control down # press Ctrl-F8
    delay 0.5 # wait a bit, UI might be slow
    key code 125 # press down to open the menu
    keystroke "german" # name of your desired language, in my case tested using German
    key code 36 # press enter
end tell
Run Code Online (Sandbox Code Playgroud)

为每种语言保存一次,切换语言名称。如果您想按不同的键,或指定与 不同的东西Ctrl-F8,请用此处的键代码替换。您还可以通过插入几个右箭头键将“输入源”菜单从其最左侧位置移动。

根据需要调用脚本,例如使用应用程序启动器(Quicksilver、Launchbar 等),或使用 Automator 将它们包装在服务中,并在System Preferences » Keyboard » Keyboard Shortcuts » Services 中为它们分配键盘快捷


Lri*_*Lri 6

一种选择是下载changeInput为 shell 命令分配快捷方式,例如changeInput U.S..

您还可以使用 KeyRemap4MacBook:

<?xml version="1.0"?>
<root>
  <vkchangeinputsourcedef>
    <name>KeyCode::VK_CHANGE_INPUTSOURCE_HIRAGANA</name>
    <inputsourceid_equal>com.apple.inputmethod.Kotoeri.Japanese</inputsourceid_equal>
  </vkchangeinputsourcedef>
  <item>
    <name>change_inputsources</name>
    <identifier>change_inputsources</identifier>
    <autogen>__KeyToKey__ KeyCode::E, VK_OPTION | ModifierFlag::NONE, KeyCode::VK_CHANGE_INPUTSOURCE_ENGLISH</autogen>
    <autogen>__KeyToKey__ KeyCode::H, VK_OPTION | ModifierFlag::NONE, KeyCode::VK_CHANGE_INPUTSOURCE_HIRAGANA</autogen>
  </item>
</root>
Run Code Online (Sandbox Code Playgroud)

请参阅private.xml 文档

VK_CHANGE_INPUTSOURCE_ENGLISH 在vkchangeinputsourcedef.xml 中定义。您可以从 EventViewer.app 中查看输入源的 ID。没有| ModifierFlag::NONE例如第一个设置也适用于 option-command-E。请参阅密钥代码值预定义设置的来源


小智 6

找到了kawa - 非常简单的应用程序,可以完全满足您的需求。设置快捷方式直接切换到所需的输入源。