Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Shift focus to desired non-java application window  RSS feed

 
Ravindra Appikatla
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I need to switch the focus from my JFrame to another running non-java application window (say Powerpoint) programmatically.
I have used the java.awt.Robot class to simulate the key presses to shift focus using

robot.keyPress(KeyEvent.VK_META);
robot.keyPress(KeyEvent.VK_TAB);
robot.keyRelease(KeyEvent.VK_TAB);
robot.keyRelease(KeyEvent.VK_META);

But, this doesn't work when I click on any other application than the desired application, before invoking the focus toggling.

Is there any way I can shift focus to any desired application window. My program runs on a Mac.

Any thoughts on this is greatly appreciated.
 
Rob Spoor
Sheriff
Posts: 21090
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think that you will have to use JNI, and invoke some native system calls that will do this for you.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!