从Java发送键盘事件到任何应用程序(屏幕键盘) [英] Sending a keyboard event from java to any application (on-screen-keyboard)
问题描述
JComponent
。当在按钮上检测到鼠标向下时,我想将特定的键盘代码发送到当前焦点的应用程序。键盘本身在一个 JFrame
中,没有装饰,并设置为永远在上。 我发现机器人类可用于模拟本机队列上的这些键盘事件。但是,在这种情况下,选择 JComponent
将意味着在 JFrame
上收到了按键,将无法在其他应用程序中收到它
如何保持屏幕键盘始终无焦点?是否可能使用其他方法发送按键?
显然,这样做的唯一方法是拥有一个JNI层,将从java转换为本机。 Java没有提供这种功能的简单方法。
对于想要学习JNI的人来说,这可能是一个有趣的概念, p>
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.
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?
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.
This could be an interesting concept for a small, third party library for someone who wants to learn JNI...
这篇关于从Java发送键盘事件到任何应用程序(屏幕键盘)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!