• Post Reply Bookmark Topic Watch Topic
  • New Topic

strange exceptions problems

 
Bilal Ali
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Respectde Friends,
I am facing a very strange problem in a very small and simple program, I am using java.awt.Robot class which can virtually press any key stroke.The program is as follows:



But I get the following exception

java.lang.IllegalArgumentException: Invalid key code

Why my program is not accepting KeyEvent.VK_COPY,it is a variable of KeyEvent class than it should be accepted, it returns integer value.Please tell the reason of exception.

Thanking You,
Bilal Ali.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you may find VK_COPY is only valid for the keyboards that have CUT,COPY,PASTE keys

instead use
obj.keyPress(KeyEvent.VK_CONTROL);
obj.keyPress(KeyEvent.VK_C);
obj.keyRelease(KeyEvent.VK_C);
obj.keyRelease(KeyEvent.VK_CONTROL);
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!