Win a copy of Event Streams in Action this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Capture global keypressed

 
Ranch Hand
Posts: 640
2
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ranchers,
I am in need to capture the global keystrokes. Even my java program is not is focus i want that the key pressed must be known to my java program. Like if my program is not in focus and I hit the F12 key, my java program window pop up.
I google this and found that I can use JNI or JNA for such purpose. JNA a bit easy than JNI.
Now I don't have any idea where to start. I didn't found any resource useful to my needs. Does someone have any link or resource where I can get a dummy code for such purposes or any useful tutorial ?
 
Sheriff
Posts: 24594
55
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's called a "keystroke logger". A program which does that can be used to keep track of what your kids are doing on the computer, or to capture the user's credit card number and send it to Russian hackers, or a variety of similar things. Anyway you're going to be using APIs for whatever operating system you're thinking of and calling them via JNA from some language other than Java. You should be able to find loads of keystroke logging code on the web but make sure that any code you download is legitimate and doesn't contain features that can be misused.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!