Forums Register Login

Shift focus to desired non-java application window

+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
I think that you will have to use JNI, and invoke some native system calls that will do this for you.
Get me the mayor's office! I need to tell her about this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 2564 times.
Similar Threads
Java Robot - how to press the keypad enter key
How to simulate Alt-Tab functionality in Java
Robot - can't get symbols: !@#$^&*()_+
Java Robots problem
How to issue command in Java program
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 04:36:54.