Results 1 to 12 of 12
  1. #1
    Addez is offline Senior Member
    Join Date
    Aug 2009
    Posts
    294
    Rep Power
    0

    Default How can i use keyevent even tho the program isnt selected?

    Hai!
    I need the program to be able to hear my key moves, even tho its not selected.
    How do I do this?

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,371
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Addez View Post
    Hai!
    I need the program to be able to hear my key moves, even tho its not selected.
    How do I do this?
    Have a look at the Robot class.

    kind regards,

    Jos

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Hm, I believe Robot will make key presses but not listen for key presses if the app doesn't have the focus. I guess I'm asking the OP to clarify his question. If listening for key presses, my money would go on using AutoIt (if a Windows app).

  4. #4
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,371
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Fubarable View Post
    Hm, I believe Robot will make key presses but not listen for key presses if the app doesn't have the focus.
    Of course that can't be done, it would be snooping if it were possible. I don't think the OP thought of those privacy/security reasons. A Robot can put events in the system's event queue but it can't listen for events that are meant for other applications.

    kind regards,

    Jos

  5. #5
    Addez is offline Senior Member
    Join Date
    Aug 2009
    Posts
    294
    Rep Power
    0

    Default

    Yes, the robot class im using, its suppose to click real fast until i press f2
    But once it clicks, the program will not be in focus and pushing f2 wont work.

    So is there a command to set focus on that jframe?
    If so then I could set the jframe visible = false
    That way it would be there, always poping up after each click, tho it wouldnt be visible =) AND it would make it so that f2 works.

    So is there a setFocus method or something?

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    What you are in essence asking for is a way to talk directly with the OS and its handling of keystrokes and what-nots. Java is built to be as operating system-agnostic as possible, and one draw back (benefit?) from this design is that it is not easy to make programs that interact directly with the OS or the hardware. So again, when I've wanted this functionality (I'm trying to automate an inflexible computerized medical record program), I've used AutoIt (a windows-only program). I think that your best bet for doing something like this is to use a program similar to AutoIt (such as WinBatch) or a JNI bridge that allows your Java app to talk to a C or C++ app are your best bets.

  7. #7
    Addez is offline Senior Member
    Join Date
    Aug 2009
    Posts
    294
    Rep Power
    0

    Default

    yea but im doing this to learn java, so and autoit uses Basic right?
    But I found this method called requestFocus()
    Its a void method but for somereason it doesnt set the focus on the jframe..

  8. #8
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    There is nothing (that I know of) in core Java that will give your application focus if it has lost it.

    yea but im doing this to learn java, ...
    One key thing to learn is Java's limitations. ;)


    ...and autoit uses Basic right?
    Kind of, sort of: AutoIt's syntax is derived from Basic just as Java's syntax is derived from C, but they are all very different programming languages.
    Last edited by Fubarable; 12-19-2009 at 04:32 PM.

  9. #9
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,371
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Addez View Post
    yea but im doing this to learn java, so and autoit uses Basic right?
    But I found this method called requestFocus()
    Its a void method but for somereason it doesnt set the focus on the jframe..
    It's a request for focus and when it is invisible (as you wrote in your previous reply) it is most certainly not going to get the focus.

    kind regards,

    Jos

  10. #10
    Addez is offline Senior Member
    Join Date
    Aug 2009
    Posts
    294
    Rep Power
    0

    Default

    Sorry to bring this up again, but I found out there is programs that is monitoring and recording your input on the computer, how do they get acces to the inputs i make?

  11. #11
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by Addez View Post
    Sorry to bring this up again, but I found out there is programs that is monitoring and recording your input on the computer, how do they get acces to the inputs i make?
    Yes, they exist in the underworld of software development and are called spyware and keystroke loggers. If you dig deeper you'll find that they are not written in Java (certainly not the keylogging part). I'm not sure how to state this any more emphatically so you'll believe us.

    Also while I don't know your motivations for studying this subject, I hope that it's not to create one of these types of applications. I doubt that anyone here will support the creation of such programs.
    Last edited by Fubarable; 12-25-2009 at 10:28 PM.

  12. #12
    Addez is offline Senior Member
    Join Date
    Aug 2009
    Posts
    294
    Rep Power
    0

    Default

    thnx, and no, Im not using it for bad purpeses, It's for my own security only.

Similar Threads

  1. My rotate 2d pos method isnt working correctly..
    By Addez in forum New To Java
    Replies: 5
    Last Post: 12-01-2009, 09:04 AM
  2. Replies: 8
    Last Post: 10-29-2009, 10:54 AM
  3. Replies: 0
    Last Post: 08-17-2009, 03:59 PM
  4. why isnt it sending value
    By snitdesne in forum New To Java
    Replies: 5
    Last Post: 10-24-2008, 07:24 PM
  5. Replies: 2
    Last Post: 03-31-2008, 05:11 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •