xyz
xyz

Reputation: 2160

Disabling the Keyboard and mouse

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

Answers (2)

Vintesh
Vintesh

Reputation: 1697

Try This - A Native Global keyboard and mouse listeners for Java. JNativeHook

Upvotes: 0

belgther
belgther

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

Related Questions