Get the VK int from an arbitrary char in java

前端 未结 8 896
孤街浪徒
孤街浪徒 2020-12-31 17:17

How do you get the VK code from a char that is a letter? It seems like you should be able to do something like javax.swing.KeyStroke.getKeyStroke(\'c\').getKeyCode()<

相关标签:
8条回答
  • 2020-12-31 18:03
    AWTKeyStroke.getAWTKeyStroke("C").getKeyCode();
    
    0 讨论(0)
  • 2020-12-31 18:03

    I am using the following code for upper-case letters and numbers in a class I wrote to extend Robot:

    
    public void typeLetterOrNumber(char c) {
        if(Character.isLetter(c)) {
            keyPress((int)c);
            keyRelease((int)c);
        }
        else if(Character.isDigit(c)) {
            keyPress(48+(int)c);
            keyRelease(48+(int)c);
        }
    }
    

    Basically, I just looked at the KeyEvent.VK_whatever values and did the appropriate math to compensate in my code.

    0 讨论(0)
提交回复
热议问题