将键盘事件从 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 send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)