Heetola
Heetola

Reputation: 6181

Java robot cannot control the whole keyboard

I tried to make a sort of keyboard controller class but the java robot seems to be unable to conrol the whole keyboard.

I tried

robot.keyPress(i);
Thread.currentThread().sleep(50);
robot.keyRelease(i);

from 0 to 255 and this key is never pressed (this key is present on all azerty keyboard).

enter image description here

Any idea why? Thanks.

Ps : you don't need to press CTRL or ALT in order to use this key, it produce this : "²"

Upvotes: 0

Views: 263

Answers (1)

vandale
vandale

Reputation: 3650

You could try creating a new window, and have it capture and print out the key codes for the keys pressed. Then run it and press the key in question. it should then print the KeyCode for it:

public static void main(String[] args) {
    JFrame frame= new JFrame();
    frame.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            System.out.println(e.getExtendedKeyCode());
        }            
    });
    frame.setBounds(0, 0, 100, 50);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
}

doing this with a virtual keyboard gave me 16777394

see http://docs.oracle.com/javase/7/docs/api/constant-values.html#java.awt.event.KeyEvent.CHAR_UNDEFINED for all the 'KeyCode' values

Upvotes: 2

Related Questions