KeyEvent Symbols

I have a question about KeyListener. When I get KeyEventand do getKeyChar(), I am tyring to compare with an asterisk *and I am going to use one of KeyEvent.VK_which works for a lot of keys.

But for this particular key and some other values ​​do not match.

* getKeyChar()will return 0x2a, but getKeyCode()will return 0x38. Define for 0x38- VK_8not VK_ASTERISK, which is equal 0x97.

Why do some key codes match, and not others. Most of all you. If I just compare the character that works ( == '*'), but I'm not sure if this is the best solution?

Thanks for the help!

+5
source share
3 answers

, - .

- , - . - , ( , Alt, Control, Shift ..).

, VK_8 , 8, * , , .

* VK_MULTIPLY - * ( ).

, , , , , .

getKeyChar(), , Shift 8 *, (Shift 8), , ( Shift) .

+5
  • KeyEvent.VK_ASTERISK - , () , * . , , - .

    If you want to use VK constants, you need to listen for events with keys and down keys and use the method KeyEvent.getKeyCode(). If you want to use characters, you listen for events with a typed type and use the method KeyEvent.getKeyChar().

    Some key codes can match a character just because it is easier to define it this way; there is no real need to do it that way.

  • You say that you have VK_8 from getKeyCodeto enter an asterisk. Have you pressed the actual sprocket key or did you have to type Shift-8?

+1
source

All Articles