对 Windows/Linux/Mac 上的 Java 程序中的全局热键做出反应?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/79658/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 11:12:57  来源:igfitidea点击:

React on global hotkey in a Java program on Windows/Linux/Mac?

javawindowslinuxmacoshotkeys

提问by Denis Tulskiy

A Java6 application sits in the system tray. It needs to be activated using a hotkey (e.g. Super-G or Ctrl-Shift-L etc) and do something (e.g. showing an input box).

Java6 应用程序位于系统托盘中。它需要使用热键(例如 Super-G 或 Ctrl-Shift-L 等)激活并执行某些操作(例如显示输入框)。

How do I do that on:

我如何做到这一点:

  • Windows (XP or Vista)
  • OS/X
  • Linux (Gnome or KDE)
  • Windows(XP 或 Vista)
  • 操作系统/X
  • Linux(Gnome 或 KDE)

回答by Denis Tulskiy

I've compiled a library for global hotkeys in java using JNA. It currently supports Windows, Linux and Mac OSX. It also supports media keys on windows and linux.

我已经使用 JNA 为 Java 中的全局热键编译了一个库。它目前支持 Windows、Linux 和 Mac OSX。它还支持 windows 和 linux 上的媒体键。

if anyone is interested, try https://github.com/tulskiy/jkeymaster

如果有人感兴趣,请尝试https://github.com/tulskiy/jkeymaster

I would appreciate any feedback.

我将不胜感激任何反馈。

Thank you.

谢谢你。

回答by Torsten Uhlmann

For Linux (X11) there is JXGrabKey: http://sourceforge.net/projects/jxgrabkey/

对于 Linux (X11),有 JXGrabKey:http: //sourceforge.net/projects/jxgrabkey/

There is also a tutorial for grabbing a global hotkey on Linux: http://ubuntuforums.org/showthread.php?t=864566

还有一个在 Linux 上获取全局热键的教程:http: //ubuntuforums.org/showthread.php?t=864566

I didn't though find a solution for OS X yet.

我还没有找到适用于 OS X 的解决方案。

To build something for all 3 platforms I'd suggest stripping down JIntellitype (it's Apache license) to it's global hotkey functionality and extending it with the OS X and X11 functionality...

要为所有 3 个平台构建一些东西,我建议将 JIntellitype(它是 Apache 许可)剥离到它的全局热键功能并使用 OS X 和 X11 功能扩展它......

回答by Antti Kissaniemi

It seems that this is not doable in a cross-platform fashion without using the native interfaces.

如果不使用本机接口,这似乎在跨平台方式中是不可行的。

On Windows, you can use the free JIntellitypelibrary.

在 Windows 上,您可以使用免费的JIntellitype库。

回答by Antti Kissaniemi

If anyone wants to do the OSX or Linux versions of the JNI part of Jintellitype I would be more than happy to add those to the JIntellitype library.

如果有人想要做 Jintellitype 的 JNI 部分的 OSX 或 Linux 版本,我很乐意将它们添加到 JIntellitype 库中。

Melloware

梅洛软件

http://www.melloware.com

http://www.melloware.com

回答by cracked_all

I found thissolution to work just great on windows. It does not require you to install any software like JIntelliType. Note that this is 32 bit dll and you can recompile for 64-bit JVM is do desire. All credits to original author of the blog.

我发现这个解决方案在 Windows 上工作得很好。它不需要您安装任何像 JIntelliType 这样的软件。请注意,这是 32 位 dll,您可以为 64 位 JVM 重新编译是确实希望的。所有学分都归功于博客的原作者。