Disable keyboard and mouse

I am new to JNA and I have this code that should block input by calling a DLL file in win7. But when I run this code, nothing happens. There is no compilation error, and I cannot understand why it does not 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 found out that I am accessing the dll file. I get error 5 (Access denied). Is there any possible way to gain access so that I can make it work?

+4
source share
2 answers

If you are running Windows Vista or Windows 7, you may need to run the program as an administrator. Create a batch file that runs your Java class to simplify the task.

+2
source

Try this - Native global keyboard and mouse listeners for Java. Jnativehook

0
source

Source: https://habr.com/ru/post/1395739/


All Articles