禁用键盘和鼠标
我是 JNA 的新手,我有这段代码,应该通过调用 win7 中的 dll 文件来阻止输入。但是当我运行这段代码时,什么也没有发生。没有编译错误,我不明白为什么它不阻止我的键盘和鼠标。请指导我。
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();
}
}
编辑:使用 Native.getLastError();我发现在访问 dll 文件时收到错误 5(访问被拒绝)。是否有任何可能的方法来获得访问权限,以便我可以使其工作?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您在 Windows Vista 或 Windows 7 上运行,您可能需要以管理员身份运行该程序。创建一个运行 Java 类的批处理文件以使事情变得更容易。
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.
试试这个 - Java 的本机全局键盘和鼠标侦听器。
JNativeHook
Try This - A Native Global keyboard and mouse listeners for Java.
JNativeHook