Reputation: 2160
I am a newbie to JNA and I have this code which is supposed to block the input by calling the dll file in win7. But when I run this code, nothing happen. There is no compilation error and I can't figure out why it doesn't block my keyboard and mouse. Please guide me.
public class BlockInput {
public static void main(String[] args) {
NativeLibrary lib = NativeLibrary.getInstance("user32");
Function fun = lib.getFunction("BlockInput");
System.out.println("Lib :" + lib + ".\nFun " + fun + ".");
fun.invoke(new Object[]{Boolean.TRUE});
try {
Thread.sleep(10000);
} catch(InterruptedException ie) {}
lib.dispose();
}
}
EDIT : With Native.getLastError(); I came to know that whicle accessing the dll file I recieve the error 5 (Access denied).Is there any possible way to gain access,so that I can make it work?
Upvotes: 4
Views: 2180
Reputation: 1697
Try This - A Native Global keyboard and mouse listeners for Java. JNativeHook
Upvotes: 0
Reputation: 2534
If you are running on Windows Vista or Windows 7, you might need to run the program as administrator. Make a batch file that runs your Java class to make things easier.
Upvotes: 2