0

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 : "²"

4

1 回答 1

2

您可以尝试创建一个新窗口,并让它捕获并打印出所按下键的键代码。然后运行它并按有问题的键。然后它应该为它打印KeyCode

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);
}

使用虚拟键盘执行此操作给了我16777394

有关所有“KeyCode”值,请参见http://docs.oracle.com/javase/7/docs/api/constant-values.html#java.awt.event.KeyEvent.CHAR_UNDEFINED

于 2013-09-14T14:42:14.347 回答