将键盘事件从 java 发送到任何应用程序(屏幕键盘)

Sending a keyboard event from java to any application (on-screen-keyboard)(将键盘事件从 java 发送到任何应用程序(屏幕键盘))
本文介绍了将键盘事件从 java 发送到任何应用程序(屏幕键盘)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我正在使用 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 发送到任何应用程序(屏幕键盘)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

How to make JComboBox selected item not changed when scrolling through its popuplist using keyboard(使用键盘滚动其弹出列表时如何使 JComboBox 所选项目不更改)
Capturing keystrokes without focus(在没有焦点的情况下捕获击键)
How can I position a layout right above the android on-screen keyboard?(如何将布局放置在 android 屏幕键盘的正上方?)
How to check for key being held down on startup in Java(如何检查在Java中启动时按住的键)
Android - Get keyboard key press(Android - 获取键盘按键)
JFormattedTextField for Double still takes characters(Double 的 JFormattedTextField 仍然需要字符)