Results 1 to 4 of 4
  1. #1
    Skurken is offline Member
    Join Date
    Feb 2011
    Posts
    2
    Rep Power
    0

    Default Getting keyEvents even though the program is not in focus

    So, I'm currently working on a nifty little tool for myself and the only thing from completing it is this little thing ;p

    What I need it to do is that whenever I press a key, regardless if the program is in focus or not, it should do a certain thing. I've got all of the code done, working, but as of right now I'm using a button instead of this KeyListener.

    I tried to do it by making the app go into the system tray but unfortunately I got an unexpected error and didnt really feel like sorting that out.

    I've googled for an answer but couldnt find anything.

    Could someone help me with this? or point out the general direction on how to do it? Is it even possible to do in Java?

    thanks in advance.
    Last edited by Skurken; 02-01-2011 at 02:14 PM. Reason: fixing type-o's

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

  3. #3
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Posts
    671
    Rep Power
    6

    Default

    The closest you can get with out of the box java is ToolKit.addAWTEventListener, and register to listen for all events.

    Fubarable is correct that you can not capture the keystrokes system wide - only those associated with your application. Keystroke loggers must run with admin/superuser privileges for obvious reasons.

    ....That said, it might be possible to create an app that fools the user into thinking s/he is interacting with other apps when in reality your app has focus, by combining Robot screen captures with full screen mode. But this sounds too much like an attempt to hack passwords, so I'm not going to offer further advice.
    Last edited by toadaly; 02-02-2011 at 05:55 AM.

  4. #4
    Skurken is offline Member
    Join Date
    Feb 2011
    Posts
    2
    Rep Power
    0

    Default

    it's not a keylogger I'm making. Dunno where you got that idea from.

    it's a screen saving app which I find very useful. it takes a screen shot and saves it to your directory of chose, and saves it as .jpg, .png, .bmp or .gif, depending on the saving options.

    As I said it does all of this and it works great, but I'm using a button on the UI which kind of makes it useless (because the idea is to just press any key and then it captures the screen and saves it, without having to copy/paste into MS Paint or something)

    thanks for the answers anyway, even if it's a bummer to find out you cant do it :/

Similar Threads

  1. Automatic convert to uppercase in keyevents
    By ashin in forum SWT / JFace
    Replies: 4
    Last Post: 08-09-2010, 01:59 PM
  2. Question about java keyevents?
    By Godsent in forum AWT / Swing
    Replies: 2
    Last Post: 10-26-2009, 09:38 PM
  3. Replies: 0
    Last Post: 04-22-2009, 05:52 AM
  4. how to focus to another JTextfield?
    By birdofprey in forum AWT / Swing
    Replies: 2
    Last Post: 04-09-2008, 01:08 PM
  5. Focus
    By Marty in forum AWT / Swing
    Replies: 1
    Last Post: 05-31-2007, 02:16 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
  •