I have the following java program which writes java in a notepad.
static int keyInput[] = { KeyEvent.VK_J, KeyEvent.VK_A, KeyEvent.VK_V,
KeyEvent.VK_A, KeyEvent.VK_SPACE };
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
Runtime.getRuntime().exec("notepad");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
/*
InputContext context = InputContext.getInstance();
System.out.println(context.getLocale().getDisplayLanguage());
System.out.println(context.getLocale().getLanguage());
context.selectInputMethod(new Locale("hi")); //hi is ISO code for hindi. Also "hin" doesn't work
*/
Robot robot=null;
try {
robot = new Robot();
} catch (AWTException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
for (int i = 0; i < keyInput.length; i++) {
robot.keyPress(keyInput[i]);
robot.delay(100);
}
}
Now I wish to write to my notepad in Hindi language. So, I manually change the language to Hindi using the Window's language bar (Note that my default language is still English) and then again run the program. Ironically what happens is that the program itself changes the language back to English (I can see the language being changed back in the language bar) and writes java in English.
But when I change the settings of my computer and set Hindi as the default language the program works and writes in Hindi.
I searched and found some information on the net about a class called Locale which could influence language input. So I included it(commented portion in the code above) but it doesn't work. Can anyone please tell me how to control the input language through java program without changing the default language? Thanks in advance.