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 10 of 10

Thread: how to make your program listen for input when it isn't the main focus?

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

    Default how to make your program listen for input when it isn't the main focus?

    basically i'm making a program that listens for user input when it isn't the main focus and then outputs keyboard presses appropriately.

    IE

    i'm typing in notepad and push f5 lets say, the program realizes this and then mimics keyboard presses using Robot...


  2. #2
    Junior Member
    Join Date
    Jun 2009
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: how to make your program listen for input when it isn't the main focus?

    using windows vista

  3. #3
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Location
    Wales, Bangor & England, Warwickshire
    Posts
    820
    My Mood
    Cynical
    Thanks
    7
    Thanked 104 Times in 90 Posts

    Default Re: how to make your program listen for input when it isn't the main focus?

    This is not possible in Pure Java due to the fact it runs on a VM. What you are after is a keyboard hook. Which must be written externally (making it platform dependant) and linked in using the likes of JNI. As it happens I am in the middle of doing this, and it's not straight forward I have to say, but that might just be my lack of experience and I am after all just a novice programmer. But I'd take a look at this thread.

    http://www.javaprogrammingforums.com...oard-hook.html

    Regards,
    Chris
    chris[at]javaprogrammingforums[dot]com

    Prifysgol Bangor University, North Wales

  4. #4
    Junior Member
    Join Date
    Jun 2009
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: how to make your program listen for input when it isn't the main focus?

    thanks for your help i've realized c++ is the better way to go

  5. #5
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: how to make your program listen for input when it isn't the main focus?

    Are you writing your own notepad-like program? If so, check here.

    If not, go with what the other people are saying.

  6. #6
    Junior Member
    Join Date
    Jun 2009
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: how to make your program listen for input when it isn't the main focus?

    i'm actually trying to make program that listens for keyboard input while it is in the background

    for instance i'm playing a game and i press f5, i want the program to realize this (while its in the background) and push certain key combinations for me

  7. #7
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Location
    Wales, Bangor & England, Warwickshire
    Posts
    820
    My Mood
    Cynical
    Thanks
    7
    Thanked 104 Times in 90 Posts

    Default Re: how to make your program listen for input when it isn't the main focus?

    So basically you are trying to write a game automation bot for something such as WoW...by the sounds of it.

    Chris
    chris[at]javaprogrammingforums[dot]com

    Prifysgol Bangor University, North Wales

  8. #8
    Junior Member
    Join Date
    Jun 2009
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: how to make your program listen for input when it isn't the main focus?

    yeah mainly for games but i dont play wow :p

  9. #9
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 286 Times in 225 Posts
    Blog Entries
    4

    Default Re: how to make your program listen for input when it isn't the main focus?

    Quote Originally Posted by Freaky Chris View Post
    So basically you are trying to write a game automation bot for something such as WoW...by the sounds of it.

    Chris
    This seems to be what most people want to do with this sort of application. I like the idea of being able to automate keystrokes in games. Programming magic...

    Shame it's not so easy in Java!
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

    Looking for a Java job? Visit - Java Programming Careers

  10. #10
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Location
    Wales, Bangor & England, Warwickshire
    Posts
    820
    My Mood
    Cynical
    Thanks
    7
    Thanked 104 Times in 90 Posts

    Default Re: how to make your program listen for input when it isn't the main focus?

    Well you never know then, maybe my C++ hook, which might I add is coming along qute nicely now just need to get down and finish it and hope that it all works since function testing is quite hard / impossible lmao so its just do and pray it works first time xD

    But ye It might be quite popular, be it for a good use or not hehe xD

    Chris
    chris[at]javaprogrammingforums[dot]com

    Prifysgol Bangor University, North Wales

Similar Threads

  1. How to Create a server socket to listen for incoming connections?
    By JavaPF in forum Java Networking Tutorials
    Replies: 3
    Last Post: October 28th, 2011, 09:02 AM
  2. Replies: 16
    Last Post: August 27th, 2010, 03:30 PM
  3. Replies: 2
    Last Post: March 23rd, 2010, 01:38 AM
  4. Java program to write game
    By GrosslyMisinformed in forum Paid Java Projects
    Replies: 3
    Last Post: January 27th, 2009, 02:33 PM
  5. Java algorithm for bank program to connect database
    By araujo3rd in forum Algorithms & Recursion
    Replies: 1
    Last Post: December 10th, 2008, 12:34 PM