2

is it even possible to build (in JAVA) application that gets keyboard strokes done on any application in windows (not in java application it self) ?!!

trojanfoe
  • 120,358
  • 21
  • 212
  • 242
Ali
  • 595
  • 4
  • 13
  • 42

5 Answers5

2

Yes I believe it is possible, but you'd have to use JNI to do it as it requires use of the Windows API as described here.

Community
  • 1
  • 1
trojanfoe
  • 120,358
  • 21
  • 212
  • 242
1

Yes, throught JNI using the Windows API. But it will not be portable.

Marcos Vasconcelos
  • 18,136
  • 30
  • 106
  • 167
0

Java by itself does not have any facility to perform this kind of thing.

You have to use JNI to create a native DLL using the Windows API that will be called by your Java code through the System.loadLibrary(String libname) method.

SirDarius
  • 41,440
  • 8
  • 86
  • 100
0

First, this is right that you can capture events on the java application window only. Second, it is wrong that your problem may be solved using JNI API only. I tried the following trick.

Create transparent full screen window. Capture events on it. When you captured the keystroke quickly disappear the window and simulate the same key press using Robot. Then create the transparent full screen window again.

This is ugly trick but it is pure java and user does not see anything. Good luck.

AlexR
  • 114,158
  • 16
  • 130
  • 208
-2

Wow.. look at the way people are answering..
3 mins ago some one suggested JNI.

Yes, throught JNI using the Windows API. But it will not be portable.

1 min ago some one else thought of answering too..

Yes I believe it is possible, but you'd have to use JNI to do it as it requires use of the Windows API as described here.

24 seconds ago someone else thought about it too...

Java by itself does not have any facility to perform this kind of thing. You have to use JNI to create a native DLL using the Windows API that will be called by your Java code through the System.loadLibrary(String libname) method.

I too think the same thing..
Use JNI dude.. :D

We need something in SF to prevent this !! If someone already suggested JNI, others shouldn't be able to post the same.. Let them add to the comment or upvote the already existing comment..!!

edit - and yeah, I am waiting for downvotes and critics here.. Let it begin!!

Shrinath
  • 7,888
  • 13
  • 48
  • 85
  • how about doing it with JNI? .. :) – bjornars Feb 08 '11 at 13:14
  • oh, and I see there is a question in meta already explaining this : http://meta.stackexchange.com/questions/49554/prevent-duplicate-answer-posts-to-the-same-question – Shrinath Feb 08 '11 at 13:17
  • My pleasure. I can't turn down a request! I think possibly since you wrote this SO has updated it so that when you're writing an answer it says "another answer has just been posted, do you want to see it?" to avoid this embarrassment. We can hope anyway :) – rogerdpack Sep 18 '13 at 23:47