Events with dll in java

Z

ZaRMaS

Hi all,

I want to develop a keylogger-like in java (not for hacking, my
programm which work in background has a hotkey to have interaction with
the selec program). Atfer many researches in the net, i must use a
native code and to load the dll with java. I don't understand how the
dll can talk with the java program :

*If dll receives a keyboard signal, how java program can have a signal
from the dll ?

Example : Dll developped in c++ receives all events from the keyboard.
How it can be transmitted to java program?
 
C

Chris Uppal

*If dll receives a keyboard signal, how java program can have a signal
from the dll ?

It's probably best to get the information out of the 'C' world of JNI and into
the Java world as quickly as possible. So I'd define a static method on some
class which your DLL invokes on every keystroke. That method (/not/ a native
method) would presumably convert the information into a more structured form (a
Keystroke object perhaps, and maybe there'd be some sort of Observer pattern),
but none of that matters to the C code.

To call a static method from C in JNI you will have to find the class using
FindClass() (it's a good idea to convert the object reference into a global
reference and cache it in your DLL -- don't forget to release it later). Also
use GetStaticMethodID() to find the method you are going to call (you can cache
that too). And to invoke the method, use one of the method invokation JNI
calls, such as CallStaticVoidMethod().

Your C code which monitors the the keyboard will presumably have to run in a
separate OS thread. You can implement that simply by starting a Java thread
which calls a native method which "never returns". Alternatively you could
create a new thread in C, and tell Java about that thread by calling
AttachThread().

-- chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,277
Latest member
VytoKetoReview

Latest Threads

Top