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

6

23

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:

  • Windows (XP or Vista)
  • OS/X
  • Linux (Gnome or KDE)
Heartbreak answered 17/9, 2008 at 3:28 Comment(1)
Spehan: Did you manage to get it done on OSX?Sidonie
S
26

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.

Spindly answered 21/6, 2011 at 7:56 Comment(1)
doesn't work any more (Windows 10, recent jna versions)Darsie
C
7

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

Convery answered 14/10, 2008 at 18:29 Comment(3)
Update: I have started to develop my own cross platform global hotkey library, called OsSupport. I have uploaded the code to BitBucket under Apache 2.0 license: bitbucket.org/agynamix/ossupport-connector. Currently OsSupport only supports Mac because of other existing solutions for Windows and Linux. However the library is designed to be cross platform and also support other things than hotkeys. For instance OsSupport can send key press events to the system in order to simulate a key press.Convery
Torsten, any interest in incorporating the Windows Jintellitype code? I am the author of that code and would love to see one unified library with Linux, Windows, Mac.Stamen
Thanks Torsten! However I cannot figure out how to use this on the Mac. Could you please provide a Readme or something? I am interested mainly in capturing the media keys.Barreto
A
6

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.

Argyres answered 17/9, 2008 at 3:33 Comment(0)
S
5

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

Stamen answered 27/10, 2008 at 17:31 Comment(0)
C
1

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.

Cowart answered 23/5, 2011 at 10:48 Comment(0)
S
0

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

Sebastian answered 29/11, 2020 at 23:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.