为系统托盘中的Java程序创建键盘挂钩 [英] Creating a keyboard hook for a Java program that sits in the System Tray
问题描述
基本上我有一个在系统托盘中运行的Java程序,想要添加它,因此,如果用户按下说CTRL + SHIFT + 1,它将选择位于托盘中的Java程序的右键单击选项之一
Basically I have a java program that runs in the system tray and would like to add make it so if the user pressed say CTRL+SHIFT+1 it selects one of the right click options of the java program that sits in the tray.
我想我正在寻找的是有关此操作的教程,或者最简单的方法是什么.我以前从未做过这样的事情,所以可能有某种noobie教程吗?
I guess what I'm looking for is a tutorial on doing this, or what the simplest approach would be. I have never done something like this before, so possibly some sort of noobie tutorial?
谢谢
推荐答案
因此,创建键盘挂钩并不像看起来那样容易,为了安全起见,java并没有提供与系统事件进行交互的直接方法;因为它可能导致与JVM,系统内存和Java Framework的可移植性有关的严重问题.
so , creating a keyboard hook isn't as easy as it looks , java doesn't provide a direct way to interact with the system events for purposes of security ; as it might lead to serious problems concerning the JVM , sysytem's memory and the portability of Java Framework..
您有4种制作全局键盘挂钩的方法:
you have 4 ways to make global keyboard hooks :
1-学习 JNI /
1- Learn JNI / JNA , and I prefer JNA since its much easier than JNI , in both cases you shall deal with .dll files.
2-使用JIntellitype,正如您所说,它会产生一些问题.
2 - Use JIntellitype , which - as you said - issues some problems.
3- Sergei Biletnikov的优雅解决方案这里.
3- the elegant solution by Sergei Biletnikov here.
4-忽略Java,尝试使用Autoit V3(我不确定100%的正确性,但我认为您可以将信号/事件从Autoit发送到Java应用程序,因此Autoit只能充当捕获该问题的桥梁.全局按键)
4- ignore Java , and try Autoit V3 ( I'm not 100% sure about it , but I think you could send signals/events from Autoit to your Java app , so Autoit would just work as a bridge that catches the global key strokes)
这篇关于为系统托盘中的Java程序创建键盘挂钩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!