This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Typing special character using Robot class  RSS feed

 
selva nayagam.K
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI all,

I have crated onscreen keyboard. I could simulate the keypress for alpaha and numeric key but for the special character it is not working.
Code sample
// For #
robot.keyPress(KeyEvent.VK_SHIFT);
robot.keyPress(KeyEvent.VK_NUMBER_SIGN);
robot.keyRelease(KeyEvent.VK_NUMBER_SIGN);
robot.keyRelease(KeyEvent.VK_SHIFT);
// For @
robot.keyPress(KeyEvent.VK_SHIFT);
robot.keyPress(KeyEvent.VK_AT);
robot.keyRelease(KeyEvent.VK_AT);
robot.keyRelease(KeyEvent.VK_SHIFT);

I get the following error
Exception in thread "main" java.lang.IllegalArgumentException: Invalid key code
at sun.awt.windows.WRobotPeer.keyPress(Native Method)
at java.awt.Robot.keyPress(Unknown Source)
at com.perfint.virtualkeyboard.Test.main(Test.java:15)
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
# isn't a key on most keyboards, it's SHIFT+3, likewise @ is SHIFT+2. VK_NUMBER_SIGN and VK_AT only work if they have their own keys.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!