how to read keyboard and mouse input when window not in focus( if possible?)

Well, first off I know a lot of you think I am writing keylogger, and I s’pose I technically am. BUT not for any illegal intentions I assure you.

My plan is to write 2 programs, on the reads input, and then saves everything I did (or atleast the basics of it), and then another that reads the file and does the stuff(this one I know how to do).

But when I thought about itm ore, I realized that I wouldn’t be able to listen to the input because my program would not be in focus.

So, if anybody has any suggestions, I would be very grateful :slight_smile:

Thanks in advance,
h3ckboy

I don’t believe this is possible with the current standard Java library.

here


package yourpckage;

class yourclass {
 public static native int GetAsyncKeyState ( int v );
}

and


JNIEXPORT jint JNICALL Java_yourpackage_yourclass_GetAsyncKeyState
  (JNIEnv *, jclass, jint v) { return GetAsyncKeyState(v); }

remember to #include < windows.h > !!

example of usage:


for (int i = 0; i < 256; i++) {
 final int vk = VK_BASE + i;
 if (yourpackage.yourclass.GetAsyncKeyState(vk) > 0) {
   fireKeyDown(vk);
 }
}

define VK_BASE to be the base of all virtual keys you want to read.

  • David

All that code is necessary and stuff, but don’t forget to explain how to compile the C code, link it to Java using javah, and using System.loadLibrary

JInput

JInput soudns much simpler :). I’ll google around for stuff about that, and I think there are tut’s here.

Thank you dx4 though :). If I run into trouble I will give that a deeper look

[EDIT]
haha, a quick google search sent me right back to javagaming :slight_smile:

JInput will do it.

On windows you’ll need to exclusively use the directx plugin, which captures mouse and keyboard input for the system rather than a window. There are details on how to do that in the JInput forum on JGO :slight_smile:

Endolf

aight, thanks for the tip :slight_smile: