0

I looking for a solution where I can "press" two keys at the same time using Java or .NET. Recently I have tried below code in Java which is working perfectly fine on one key. Here is the code for one key

r.keyPress(KeyEvent.VK_R);

Upon execution of this code it press letter 'R'. Now what I'm looking is to press "Windows+R" keys or say a combination of multiple keys not more than two keys at the same time.

Duncan Jones
  • 67,400
  • 29
  • 193
  • 254
user3498003
  • 21
  • 1
  • 4
  • @user3498003 what is `r` object? show some more code – Dima Apr 04 '14 at 12:36
  • @DimaGoltsman It is almost certainly the [`Robot`](http://docs.oracle.com/javase/7/docs/api/java/awt/Robot.html) class, although I agree it would have been nice for that to be explained in the question. – Duncan Jones Apr 04 '14 at 12:36

1 Answers1

4

ok, from the doc of Robot class, just do:

r.keyPress(KeyEvent.VK_WINDOWS);
r.keyPress(KeyEvent.VK_R);  // VK_WINDOWS key still pressed
r.keyRelease(KeyEvent.VK_R);
r.keyRelease(KeyEvent.VK_WINDOWS);

the keyPress method does not relese the key, so this should work

Dima
  • 8,586
  • 4
  • 28
  • 57