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 发送到任何应用程序(屏幕键盘)
				
        
 
            
        基础教程推荐
- 如何在 JFrame 中覆盖 windowsClosing 事件 2022-01-01
 - 不推荐使用 Api 注释的描述 2022-01-01
 - Java Swing计时器未清除 2022-01-01
 - 从 python 访问 JVM 2022-01-01
 - 验证是否调用了所有 getter 方法 2022-01-01
 - 在 Java 中创建日期的正确方法是什么? 2022-01-01
 - Java 实例变量在两个语句中声明和初始化 2022-01-01
 - 如何在 Spring @Value 注解中正确指定默认值? 2022-01-01
 - 大摇大摆的枚举 2022-01-01
 - 多个组件的复杂布局 2022-01-01
 
    	
    	
    	
    	
    	
    	
    	
    	
						
						
						
						
						
				
				
				
				