问题标签 [jnativehook]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
53 浏览

java - 当使用 throws 关键字调用 void 时,所有抛出的错误都适用于我调用 void 的位置

我目前正在尝试使用 Java 制作一个换档键持有人,使用重音作为切换键,而机器人是我能找到的唯一简单的方法。该程序执行顾名思义,并为我按住 shift 键。如果您想知道这将在哪里有用,请制作用于星界建筑的程序,因为有大写锁定。但是,当使用机器人时,我必须抛出一些异常,但它们随后会出现在我称之为 void 的地方

我找不到任何解决方案,可能是因为我正在使用 JNativeHook 库来创建一个对坟墓符号做出反应的键盘记录器。我还是个新手,我从网上的片段中拼凑了很多。

这就是我的错误的来源,完整的程序在这里可用 我会发布一个最小的可重现示例,但我不能,因为我不知道哪些部分对这一部分的功能至关重要。

我希望它没有错误,但Robot()如果我不抛出它们就会有异常,并且toggle();有我抛出的任何异常public static void toggle()。我对机器人以外的方法持开放态度,但我找不到其他方法。

0 投票
1 回答
155 浏览

java - 如何防止或删除后台 Java 进程中的前台文本输入?

我正在创建一个后台 Java 程序,该程序将从支持 USB 的 NFC 阅读器获取输入,并使用在其上找到的数据(一个 10 位数字)执行 API 请求。然而,阅读器没有自己的软件,就像键盘一样,将扫描的数字输入到任何选定的文本字段中。

使用JNativeHook,我能够创建一个键盘记录器类型的软件,它会等到快速输入 10 位数字,然后发出 API 请求。这种方法效果很好,但是数字仍然输入到任何前景/选定的文本字段中,所以我一直在寻找解决这个问题的方法。

我想知道是否有一种方法可以在显示所有文本输入之前验证它们,或者在输入该数字后立即退格。

如果您想查看整个(小)项目,请点击此处

CardReaderKeylogger.java

0 投票
4 回答
55 浏览

java - 在线程中运行时循环不起作用

所以基本上我试图让这个while循环在这个线程中运行,它应该在“激活”评估为真时激活,但由于某种原因它不起作用。“激活”是布尔值,当用户按下鼠标按钮时激活(我为此设置了监听器)。如果有人想知道我在这个项目中使用 jnativehook 库。任何帮助或解释将不胜感激。

0 投票
0 回答
151 浏览

java - JavaFX 和 jnativehook 库冲突

我使用 jnativehook 进行全局键盘监听。我在 JavaFX 11 中创建了 GUI。我有一个 TextField 来定义按下指定组合键后创建的文件的名称。

问题是我无法通过键盘编辑 TextField 中的文本。我可以用鼠标删除或粘贴文本,但不能用键盘。

我为全局键盘监听创建了一个单独的线程。我的想法是在 TextField 聚焦时停止这个线程。不幸的是,我的尝试失败了。

这是导致类似问题的最小可重复示例:

主.java

控制器.java

0 投票
1 回答
235 浏览

java - 如何在 intellj 上正确编译 jnativehook?

我很确定我一切正常,但它不会编译网站上发布的示例

这是我的 POM.xml

这是 cmd 的错误输出:

如果您想尝试一下,这是我的github 。找到文件 GlobalKeyListenerExample.java 并尝试编译它。

0 投票
1 回答
410 浏览

java - 如何按需停用 jnativehook?

如果我的理解对我有用,可以使用以下两个命令打开和关闭正确的 jnativehook:

GlobalScreen.removeNativeKeyListener(this); //这将其关闭

GlobalScreen.addNativeKeyListener(this);//这会再次打开它

按照这个逻辑,下面的程序:

据我了解,它应该打印这样的东西。

相反,我得到了这个:

发生的事情是,即使我使用了命令,nativehook 也会不断重新注册所有输入

GlobalScreen.removeNativeKeyListener(this);

当我用run2()将它添加回来时,程序会遍历我在输入时给它的所有按键(以及它们调用的方法,在这种情况下是按下“a”时的run())。为什么会有这种行为?

0 投票
0 回答
44 浏览

java - 如何抑制其他应用程序的 F 键

我创建了一个GlobalScreen用于addNativeKeyListener. (jnativehook 库)

当我按 F5 时,它会执行一个代码。问题是,如果我将重点放在其他应用程序上,它也会为重点应用程序执行功能。(例如 Chrome 会刷新网站)

有没有办法抑制这些功能并让我的应用程序完全控制 F5?

我用它来听 F5 keyPress globaly(即使我的应用程序失去焦点):

从我的主要我必须打电话:

0 投票
0 回答
182 浏览

java - JAVA - 为什么 JNativeHook 在 Windows 上不起作用?

我正在 JAVA 中创建一个简单的按键记录器,因此我使用 JNativeHook 库来记录键入的按键。我的程序在 Ubuntu 上运行正常,但是当我尝试在 Windows 上启动它时,出现以下错误:

你知道如何修复这个错误吗?(我使用AZERTY键盘测试我的代码,我的项目的JAVA版本是11.0.2,我有JNativeHook的2.1.0版本)

感谢您的回答。

0 投票
1 回答
84 浏览

java - Case of the confounding key press caper

Background

Developing a rudimentary, open-source keyboard and mouse on-screen display desktop application for screen casting, called KmCaster:

Screen Casting Preview

The application uses the JNativeHook library to receive global keyboard and mouse events, because Swing's Key and Mouse listeners are restricted to receiving events directed at the application itself.

Problem

When the application loses focus, the user interface shows intermittent key presses, rather than every key press. Yet the console shows that the application has received every key press.

Code

A short, self-contained, compileable example:

The code above produces a small window that, when run, demonstrates the problem:

Harness Screenshot

Be sure to type into any other window to see the perplexing loss of key presses within the demo application.

Environment

  • OpenJDK version "14.0.1" 2020-04-14, 64-bit
  • XFCE
  • Arch Linux
  • JNativeHook 2.1.0

Details

JNativeHook runs in its own thread, but using invokeLater (or invokeAndWait?) should issue the UI update on Swing's event thread.

The call to disableNativeHookLogger() isn't relevant, it merely keeps the console clean when running the demo.

Console Output

Here is the console output when the application has focus:

Here is the console output when the application loses focus:

So it's clear that no keyboard events are missing when nativeKeyPressed is called, regardless of whether the application has focus. That is, neither JNativeHook nor its event bubbling via JNI appears to be the culprit.

Question

What needs to change so that the JLabel text is updated for every key press regardless of whether the application has focus?

Ideas

Some items that help include:

  • Call getDefaultToolkit().sync(); to flush the rendering pipeline explicitly.
  • Call paintImmediately( getBounds() ) on the label.

The first item seems to make a huge difference, but some keys still appear to be missing (although it could be that I'm typing too quickly). It makes sense that preventing the rendering pipeline from merging paint requests avoids loss of key strokes.

Research

Resources related to this issue:

0 投票
1 回答
567 浏览

java - 未找到 JNativeHook 类

我需要一个 KeyListener,它也可以在一个集中的 GUI 组件之外工作,所以在进行研究之后,我遇到了 JNativeHook 库。但是,只要我下载 ZIB 文件(从这里)并将 jnativehook-2.1.0.jar 添加到我的 Eclipse 项目(属性 -> Java 构建路径 -> 库 -> 添加外部 Jar),运行时会出现错误消息测试程序。

错误:无法找到或加载主类 key.GlobalKeyListenerExample 原因:java.lang.NoClassDefFoundError: org/jnativehook/keyboard/NativeKeyListener

这是我第一次使用外部 Jar,所以我想问一下我是否做错了什么,或者我需要做什么来解决这个问题。

我的程序: