This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes Detecting Key Presses in Windows (without focus) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Detecting Key Presses in Windows (without focus)" Watch "Detecting Key Presses in Windows (without focus)" New topic
Author

Detecting Key Presses in Windows (without focus)

Micho Lee
Greenhorn

Joined: Oct 21, 2003
Posts: 14
I'm writing a java application that runs in the background in a Windows XP environment. I need a way for the application to detect when certain keys have been pressed on the keyboard even when it is not in focus. Kind of like a key logger would do, I need it to detect any keys that might be pressed. Does anyone know how to implement such a "global" key listener so that a key press can be captured at any/all times within Windows?

Help (esp exaple code) would be much appreciated. Thanks in advance!
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
If I were writing such a program, I probably use C or C++ instead of Java. This is because it sounds highly dependent on platform-specific code. Perhaps this is possible using AWT listeners, but I think KeyListener requires the application to have focus.

Layne


Java API Documentation
The Java Tutorial
James Carman
Ranch Hand

Joined: Feb 20, 2001
Posts: 580
This sounds like an awfully dangerous application to write (sounds a lot like spyware). Why do you need to do such a thing?


James Carman, President<br />Carman Consulting, Inc.
Paulo Pontes
Greenhorn

Joined: Dec 06, 2004
Posts: 20
I need the same thing!

my app captures the interation between the user and some other app to mimic it later with some changes (it's a bot/macro tool for mmorps )
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Still not a Java thing. The spyware people call programs like that "Keystroke Loggers", so you could use that term if you're doing internet searches.
Ken Blair
Ranch Hand

Joined: Jul 15, 2003
Posts: 1078
Originally posted by Paulo Pontes:
I need the same thing!

my app captures the interation between the user and some other app to mimic it later with some changes (it's a bot/macro tool for mmorps )


Suddenly the reason for the image question becomes apparent. Which one is this for? SWG? CoV? CoH? WoW? AC? AC2? EQ? EQ2? DAoC? AO? NC? UO? L? L2? PS? I remember when there was only three, now look at all those acronyms! I probably don't want to know, I'd just have to come kill you. In the game that is. There's plenty of macro software out there for Windows, I suggest using one of those unless you're bound and determined to write your own.
 
 
subject: Detecting Key Presses in Windows (without focus)
 
Similar Threads
Detecting Key Presses in Windows (without focus)
Key event
Key Tracking
Detecting control or alt key pressed
Tab Key and KeyListeners