0

I'm writing a virtual keyboard for my application and I'm using Java robot in order to simulate the keypress event of each keyboard button. Everything is right except that I can't find the keycode for European special chars, specifically the italian ones. Scanning every possible code I've found that:

à is KeyEvent.VK_DEAD_ABOVERING
ì is KeyEvent.VK_DEAD_CIRCUMFLEX
ò is KeyEvent.VK_DEAD_CEDILLA
ù is KeyEvent.VK_DEAD_GRAVE

but I'm missing the keycode for "è", it appears like if no code can produce this char.

I've also already tried to get the missing code using tools that prints out each key pressed on the phisical keyboard, but I get "unkown" for each one of the above chars (including the "è").

Here is a piece of code to test it

package robottest;
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;

public class RobotTest {

    private static Robot robot;

    public static void main(String[] args) {
        // TODO code application logic here
        try {
            robot = new Robot();
            int keyCode = KeyEvent.VK_DEAD_CARON;
            robot.keyPress(keyCode);
            robot.keyRelease(keyCode);

        } catch (AWTException ex) {
            System.out.println("Exception"+ex);
        }
    }
}

It is minimal, you can compile it and run with

java -jar RobotTest.jar

Here is what i get modifying my source to act as a kind "code scanner" ...

package robottest;
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;
import javafx.scene.input.KeyCode;

public class RobotTest {

    private static Robot robot;

    public static void main(String[] args) {
        // TODO code application logic here
        try {
            robot = new Robot();
/*            int keyCode = KeyEvent.VK_DEAD_BREVE;
            robot.keyPress(keyCode);
            robot.keyRelease(keyCode);                
*/
            for (int keyCode = KeyEvent.VK_DEAD_GRAVE; keyCode <KeyEvent.VK_DEAD_GRAVE+20; keyCode++) {
                System.out.print("Code "+keyCode+" ");
                robot.keyPress(keyCode);
                robot.keyRelease(keyCode);         
                System.out.println("");                
            }

        } catch (AWTException ex) {
            System.out.println("Exception"+ex);
        }
    }
}

The output is:

Code 128 ù
Code 129 ,
Code 130 ì
Code 131 3
Code 132 -
Code 133 ù
Code 134 
Code 135 .
Code 136 à
Code 137 2
Code 138 
Code 139 ò
Code 140 0
Code 141 
Code 142 
Code 143 
Code 144 
Code 145 
Code 146 
Code 147 

1 Answers1

0

The value you are looking for is VK_DEAD_CARON, code 138

You can find any value associated to a character starting from ASCII table: search for its numeric value, and then you will find the associated variable in java KeyEvent

Another possibility is to implement a custom keyboard

Leviand
  • 2,745
  • 4
  • 29
  • 43
  • It doesn't work, nothing is printed using VK_DEAD_CARON – Thomas Paoloni May 27 '19 at 12:50
  • could you please add to the question the code that you are using for testing? – Leviand May 27 '19 at 12:52
  • I've added it to the main text question – Thomas Paoloni May 27 '19 at 13:06
  • another strange thing is both VK_DEAD_GRAVE (0x80) and VK_DEAD_BREVE (0x85) produces the same "ù", it is like duplicate ... – Thomas Paoloni May 27 '19 at 13:19
  • with the code you provided me, I'm getting `java.lang.IllegalArgumentException: Invalid key code` , even with the first 4 example you provided at the beginning of the question ... – Leviand May 27 '19 at 13:21
  • I think it is because of your locale setting. Java robot doesn't simply prints a char to the screen but it simulates the press of a keyboard button, as a low level event, maybe you don't have those buttons configured in your actual layout. – Thomas Paoloni May 27 '19 at 13:51
  • 1
    As you said, something is not working as expected (ù char), maybe it's better to change strategy: try implementing custom keyboard, take a look here -> https://stackoverflow.com/a/20979488/1984767 – Leviand May 27 '19 at 13:58