Results 1 to 5 of 5
  1. #1
    totalspelnerd is offline Member
    Join Date
    Mar 2012
    Location
    Sweden
    Posts
    88
    Rep Power
    0

    Default Listen to keys at all times

    I want to create a program that keeps track on how many times I've clicked a certain button and the total of all button clicks. Pretty simple idea but hard for me to execute.
    The hard part is making the program listen to all key presses at all times, even when I'm on the internet or playing a game. When you use KeyListener you need to be focused on a component for it to listen.

    So my question is how I can make KeyListener that listens to every key press all the time and not only when the program is focused.

    ps: I don't want to use a software already out there, that takes away the fun of it.
    pss: Would be appreciated if you post it as simple as possible so I can understand.

    Thanks for putting down your precious time helping me.

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,041
    Rep Power
    10

    Default Re: Listen to keys at all times

    The short answer is that this is going to be pretty hard in Java.

    The longer answer is that you might want to look into using JNI to accomplish this.

    Another short answer is that you can't write spyware in Java.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,365
    Rep Power
    6

    Default Re: Listen to keys at all times

    "Another short answer is that you can't write spyware in Java. "
    That, wrong tool for the job. This is the job for a development platform native to the operating system in which you want to achieve this. For example for Windows:

    Processing Global Mouse and Keyboard Hooks in C# - CodeProject
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  4. #4
    totalspelnerd is offline Member
    Join Date
    Mar 2012
    Location
    Sweden
    Posts
    88
    Rep Power
    0

    Default Re: Listen to keys at all times

    oh well, if I can't make it in java I don't feel like making it. Barely know anything about another language but thanks for the help anyways.

  5. #5
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,365
    Rep Power
    6

    Default Re: Listen to keys at all times

    if lack of knowledge holds you back from doing something, you won't ever do anything that is remotely interesting. But good luck.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. Replies: 0
    Last Post: 05-12-2013, 11:51 AM
  2. Listen for changes in a custom Object?
    By ozzyman in forum New To Java
    Replies: 12
    Last Post: 05-17-2011, 12:25 AM
  3. Listen for changes in a JTextField
    By matzahboy in forum AWT / Swing
    Replies: 5
    Last Post: 10-13-2009, 05:15 PM
  4. Cannot Listen TAB key
    By sh4dyPT in forum AWT / Swing
    Replies: 5
    Last Post: 07-16-2009, 02:45 PM

Posting Permissions

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