Search code examples
javac++keyboard-hook

C++/Java - Keyboard Hook


I am attempting to create a keyboard hook to use in Java. After some research, I realized I will need some things from C++. I don't have much experience with C++, I have only messed with the syntax for a short while. How would I do this in C++? And how would I make the C++ code interact with the Java code? Any help is greatly appreciated.


Solution

  • I'm not exactly sure what you want for your C++ code, but here's how you would make it work with Java:

    Look into JNI, it'll explain how to execute native code through Java

    http://java.sun.com/developer/onlineTraining/Programming/JDCBook/jni.html

    Essentially, you use a tool to create glue headers that you include in your C++ application. The Java code will automatically call the native library when you call a native function.

    Also keep in mind that there's a speed penalty for going from native to java layer.