我想改变目前正在编程使用的windows键盘。
我正在为一种东方语言编写一个字典程序,我想让它在用户单击不同的表列时切换到另一个键盘。
我对此进行了研究,发现了使用Windows PowerShell和本机C++代码的示例。PowerShell似乎不工作,我也不熟悉原生的Windows API和C。任何关于如何用Java语言完成这项工作的帮助都将不胜感激。
发布于 2013-01-24 21:43:55
这里有一篇博客文章解释了如何做到这一点:change input method
简而言之:
yourMainJFrame.getInputContext().selectInputMethod(new Locale("fa", "IR"));
发布于 2021-05-07 02:32:33
上面的方法对我不起作用,所以我使用原始的方式使用Robot
public static void switchKeyboardLanguage()
{
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
try
{
Robot robot = new Robot();
robot.keyPress(KeyEvent.VK_ALT);
robot.keyPress(KeyEvent.VK_SHIFT);
robot.delay(10);
robot.keyRelease(KeyEvent.VK_ALT);
robot.keyRelease(KeyEvent.VK_SHIFT);
}
catch (AWTException e)
{
LogUtils.logError("Failed to use Robot, got exception: ", e);
}
}
});
}
https://stackoverflow.com/questions/14501842
复制相似问题