Skip to content

dstjacques/JHotKeys

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JHotKeys is a Java wrapper around the JIntellitype and JXGrabKey libraries which utilize JNI on their respective platforms.

Using it lets any Java application define global hotkeys that will work on Windows, Linux, and other Unix-like platforms.

License

GNU LGPLv3. See COPYING and COPYING.LESSER for more information.

Included Dependencies

Binaries of the dependent libraries JIntellitype and JXGrabKey are already included in lib/windows and lib/unix in completely unmodified form.

This is done for convenience to make getting up and running easier. You are welcome to build newer versions of these if so desired and replace the older version in its respective folder.

Their source code is open and readily available via their respective websites.

How to build JHotKeys

The JHotKeys source and the included example can all be built by using the makefile provided in this directory.

make

How to use JHotKeys

Place the lib folder somewhere in your application's directory structure

The lib folder should contain JHotKeys.jar (if not you have to build it from source) and its subdirectories should have the wrapped libraries for Windows (JIntellitype) and Linux (JXGrabKey).

Use the following imports.

import com.dstjacques.jhotkeys.JHotKeys;
import com.dstjacques.jhotkeys.JHotKeyListener;

Create a JHotKeys object specifying where the lib folder is located with regards to the current path.

JHotKeys hotkeys = new JHotKeys(PATH_TO_LIB);

Register a global hotkey for the 'A' key without any modifiers.

hotkeys.registerHotKey(0, 0, (int)'A');

Implement a key listener with actions that will occur when the hotkeys you define are used.

      JHotKeyListener hotkeyListener = new JHotKeyListener(){
         public void onHotKey(int id) {
            if(id == 0)
            {
               System.out.println("You pressed 'A'");
            }
         }
      };

Add the key listener.

      hotkeys.addHotKeyListener(hotkeyListener);

For a concrete example see examples/GlobalHotKeyExample.java.

About

Global Hotkeys for Java

Resources

License

LGPL-3.0, GPL-3.0 licenses found

Licenses found

LGPL-3.0
COPYING.LESSER
GPL-3.0
COPYING

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published