Why are some KeyEvent keycodes throwing “IllegalArgumentException: Invalid key code”?

后端 未结 2 1637
清酒与你
清酒与你 2020-12-07 03:32

I\'m trying to automate some processes using Robot and it seems certain keycodes (only symbols that require you to hold shift when typing it normally) in

相关标签:
2条回答
  • 2020-12-07 04:19

    Because like the documentation for Robot.keyPress says, an IllegalArgumentException is thrown when the keycode doesn't represent a valid key, and VK_EXCLAMATION_MARK is not a valid key.

    Keycodes are used to represent two things: keys on the keyboard, and "a character was typed" events. Typing a character often requires more than one keypress (in sequence, or simultaneously, or both). But Robot.keyPress simulates the act of pressing a key (hence the name), not the act of typing a character.

    For more information, see the documentation for KeyEvent: http://download.oracle.com/javase/6/docs/api/java/awt/event/KeyEvent.html

    0 讨论(0)
  • 2020-12-07 04:21

    I don't know Robot, but isn't that because it needs to be two keys pressed to an exclamation mark to be inserted.

    There are no exclamation mark key on the keyboards.

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