Stephan Wissel
Stephan Wissel

Reputation:

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

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).

How do I do that on:

Upvotes: 23

Views: 16666

Answers (6)

vda8888
vda8888

Reputation: 707

I've written a Java library for global key/mouse events here. This works for Windows, Linux X11, and OSX.

https://github.com/repeats/SimpleNativeHooks

Upvotes: 0

Denis Tulskiy
Denis Tulskiy

Reputation: 19187

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.

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

I would appreciate any feedback.

Thank you.

Upvotes: 26

cracked_all
cracked_all

Reputation: 1341

I found this solution 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.

Upvotes: 1

Melloware
Melloware

Reputation:

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.

Melloware

http://www.melloware.com

Upvotes: 5

Torsten Uhlmann
Torsten Uhlmann

Reputation: 645

For Linux (X11) there is 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

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

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...

Upvotes: 7

Antti Kissaniemi
Antti Kissaniemi

Reputation: 19313

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

On Windows, you can use the free JIntellitype library.

Upvotes: 6

Related Questions