Changing Keyboard Input language in Java

2019-07-26 08:28发布

问题:

Is there a way to set/change the keyboard input language in Java (eg from English to German)?

Example Use Case: Script to be used for playback is recorded (typed in) on a German keyboard. The automated playback is done on a English keyboard...fails if keyboard is not set to German automatically before script is run.

回答1:

The keyboard input map is managed entirely by the operating system on every platform that I'm familiar with. Java provides no APIs for manipulating this in a cross-platform manner. I would investigate native APIs that you could manipulate via JNA, or even (if you're feeling dirty) shelling out to call some platform-specific command which does what you need.

You're not going to find a solution within the JDK standard lib.



回答2:

In java, you can use the InputContext class. See its API or do google search on InputContext.