Sending a keyboard event from java to any application (on-screen-keyboard)(将键盘事件从 java 发送到任何应用程序(屏幕键盘))
问题描述
我正在使用 java 开发屏幕键盘.这个键盘对每个可能的键都有一个 JComponent
.当在按钮上检测到鼠标按下时,我想将特定的键盘代码发送到当前处于焦点的应用程序.键盘本身位于 JFrame
内,没有任何装饰,并设置为始终位于顶部.
I am working on developing an on-screen keyboard with java. This keyboard has a JComponent
for every possible key. When a mouse down is detected on the button, I want to send a specific keyboard code to the application currently on focus. The keyboard itself is within a JFrame
with no decorations and set to always-on-top.
我发现Robot类可以用来模拟原生队列上的这些键盘事件.但是,在这种情况下,选择 JComponent
将意味着在 JFrame
上接收到按键,而我将无法在其他应用程序中接收到它
I found that the Robot class can be used to simulate these keyboard events on the native queue. However, in this case, selecting the JComponent
would mean that the key-press is received on the JFrame
, and I wouldn't be able to receive it in the other application
如何让我的屏幕键盘始终没有焦点"?是否可以使用另一种方法来发送按键?
How can I keep my on-screen keyboard "Always-without-focus"? Is it maybe possible to use another approach to send the key-press?
推荐答案
显然,做到这一点的唯一方法是拥有一个 JNI 层,该层将使从 java 到 native 的转换.Java 没有简单的方法来提供这样的功能.
Apparently the only way to do this is to have a JNI layer that will make the conversion from java to native. Java has no easy way to provide such funcionality.
对于想要学习 JNI 的小型第三方库来说,这可能是一个有趣的概念...
This could be an interesting concept for a small, third party library for someone who wants to learn JNI...
这篇关于将键盘事件从 java 发送到任何应用程序(屏幕键盘)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:将键盘事件从 java 发送到任何应用程序(屏幕键盘)


基础教程推荐
- 降序排序:Java Map 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01