Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: switch focus to another window

  1. #1
    Junior Member
    Join Date
    Nov 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default switch focus to another window

    hello, i'm trying to write an app to control another app in Windows, there is a keyPress method in Robot class, but i don't know how to specify which process to send the key, is there any methods to send focus to a specific window and bring it to top on desktop, therefore i can send a key to it properly?


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: switch focus to another window

    Quote Originally Posted by tuansoibk View Post
    hello, i'm trying to write an app to control another app in Windows, there is a keyPress method in Robot class, but i don't know how to specify which process to send the key, is there any methods to send focus to a specific window and bring it to top on desktop, therefore i can send a key to it properly?
    Within the same java application, you can just call the toFront() method on a Window instance. However if you wish to try and control other applications, you are probably stuck using Runtime.exec(). This would also be highly platform dependent, and you need to know the command line tools and parameters well to be able to call the appropriate commands (if they exist) to get the behavior you want.

Similar Threads

  1. switch with Enums
    By chronoz13 in forum Loops & Control Statements
    Replies: 17
    Last Post: October 8th, 2009, 08:08 PM
  2. Navigating from one window to another
    By visharaddhavle83 in forum AWT / Java Swing
    Replies: 2
    Last Post: August 6th, 2009, 07:55 AM
  3. I'm not sure how to initialize GraphicsDevice and Window
    By DotChris in forum AWT / Java Swing
    Replies: 3
    Last Post: July 15th, 2009, 09:00 AM
  4. Replies: 9
    Last Post: June 27th, 2009, 04:05 PM
  5. Facing problem with open modeless dialog from modal window
    By Divya in forum Java Theory & Questions
    Replies: 1
    Last Post: May 14th, 2009, 03:18 AM