Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Robot class press Turkish letter (Ö, ö, Ş, ş, Ü, ü, Ğ, ğ, İ, ı, Ç, ç, Ə, ə)?

I have problem with press a special letter (Turkish etc.) via java robot class. I hava a method to press keys which works as alt+keycode. I cant convert some special letters to current keycode. So how can I solve it. Thanx

For Example:

KeyStroke ks = KeyStroke.getKeyStroke('ö', 0);
 System.out.println(ks.getKeyCode());
 Output : 246
 // So alt+0246='ö'
 //but if I convert 'ş' to keycode
 //Output is 351 . So alt+351= '_' and alt+0351= '_' 
 //What is the Correct combination for 'ş'. same for 'Ş', 'ş','Ğ', 'ğ', 'İ', 'ı', 'Ə', 'ə'

KeyPress:

public void altNumpad(int... numpadCodes) {
    if (numpadCodes.length == 0) {
        return;
    }

    robot.keyPress(VK_ALT);

    for (int NUMPAD_KEY : numpadCodes) {
        robot.keyPress(NUMPAD_KEY);
        robot.keyRelease(NUMPAD_KEY);
    }

    robot.keyRelease(VK_ALT);
}
like image 650
Bertrand Avatar asked Oct 19 '22 19:10

Bertrand


2 Answers

The character numbers are defiunied in the Unicode standard. The are also used in HTML, therefore you can use this table.

Anyway if you see the character in the source code depends on the fact that the editor interprets the file correctly (UTF-8 is preferred).

Second the used editor must have a font installed that contains these characters. Hence if you type alt+0351 and get and '_' this may just be a replacement character indicating that the font misses this character.

And in the end you should tell the Java compiler that the source code is UTF-8 - just to make sure (javac -encoding utf8).

like image 147
Robert Avatar answered Oct 22 '22 08:10

Robert


I am not sure why you did

KeyStroke ks = KeyStroke.getKeyStroke('ö', 0);

Because java docs say,

public static KeyStroke getKeyStroke(Character keyChar,
                 int modifiers)
//Use 0 to specify no modifiers.

you need to pass a modifier other than 0 to the overload.

You should try to pass a modification like,

java.awt.event.InputEvent.ALT_DOWN_MASK

So probably should try,

KeyStroke ks = KeyStroke.getKeyStroke('ö', java.awt.event.InputEvent.ALT_DOWN_MASK);

Java doc as reference: http://docs.oracle.com/javase/7/docs/api/javax/swing/KeyStroke.html#getKeyStroke(char)

If you cannot properly get a output from that then you should consider the fact the character is UTF-8 This might help you in that regard, Java, Using Scanner to input characters as UTF-8, can't print text

like image 24
Ya Wang Avatar answered Oct 22 '22 09:10

Ya Wang