禁用键盘和鼠标

发布于 2025-01-04 10:53:52 字数 649 浏览 6 评论 0原文

我是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

长梦不多时 2025-01-11 10:53:52

如果您在 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.

空心空情空意 2025-01-11 10:53:52

试试这个 - Java 的本机全局键盘和鼠标侦听器。
JNativeHook

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文