Coder Social home page Coder Social logo

jjybdx4il / jkeymaster Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tulskiy/jkeymaster

0.0 1.0 0.0 440 KB

A library for registering global hotkeys in java with JNA. The goal is to support X11-based platforms, Windows and MacOSX

License: GNU Lesser General Public License v3.0

Java 100.00%

jkeymaster's Introduction

JKeyMaster

Build Status

This is a java library that provides single interface to register Global Hotkeys for several platforms:

  • Windows
  • X11-based systems (in theory, only tested on some Linux distros and PCBSD)
  • Mac OSX

Building

You will need Java 1.6+ and Maven to build

mvn clean install

for jkeymaster-dbus, you will need to download and build a few dependencies

git clone [email protected]:tulskiy/libmatthew-java.git
cd libmatthew-java
mvn clean install

git clone [email protected]:tulskiy/dbus-java.git
cd dbus-java
mvn clean install -DskipTests

then you can build from project root with profile linux

mvn -P linux clean install 

Maven

Release version:

<dependencies>
    <dependency>
        <groupId>com.github.tulskiy</groupId>
        <artifactId>jkeymaster</artifactId>
        <version>1.2</version>
    </dependency>
</dependencies>

Snapshot version:

<dependencies>
    <dependency>
        <groupId>com.github.tulskiy</groupId>
        <artifactId>jkeymaster</artifactId>
        <version>1.3-SNAPSHOT</version>
    </dependency>
</dependencies>

<repositories>
    <repository>
        <id>snapshots-repo</id>
        <url>https://oss.sonatype.org/content/repositories/snapshots</url>
    </repository>
</repositories>

Logging

JKeyMaster uses slf4j as the logging framework. To get output from the library you should include a slf4j binding to your classpath.

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-jdk14</artifactId>
    <version>1.7.13</version>
</dependency>

Testing

To test that the library works on your system, run the jar file

java -cp jkeymaster-1.2.jar com.tulskiy.keymaster.AWTTest

It will open a simple window. At the top is a field that listens to key presses. Choose your hotkey and press Grab button. Check log output to see if it failed. If the log is clean, you should be able to press the hotkey anywhere and it should popup a message.

There's also a Grab media keys button that should register media keys (only Windows and Linux) - Play/Pause, Next Track, Previous Track, Stop.

If you get UnsatisfiedLinkError on linux, it is probable that you have an older jna version installed, see #19 you will need to either remove libjna-java from your system, or add -Djna.nosys=true to jvm args

API Example

Main class is Provider. To get provider for current platform:

Provider provider = Provider.getCurrentProvider(useSwingEventQueue);

where useSwingEventQueue is a boolean parameter specifying whether to fire events on swing event queue or just simple thread. Usefull when your hotkey listener will directly access or modify some swing components.

Provider supports two methods for registering hotkeys - one accepts AWT KeyStroke:

provider.register(KeyStroke.getKeyStroke("control shift PLUS"), listener);

the other accepts a MediaKey parameter:

provider.register(MediaKey.MEDIA_NEXT_TRACK, listener);

For simplicity reasons, it is currently impossible to unregister some particular hotkey, but all hotkeys can be reset.

When you're done using the library, you need to reset hotkeys and stop the provider:

provider.reset();
provider.stop();

DBus

On some systems DBus does not allow registering hotkeys for media keys. To fix this, you can use GnomeMediaProvider class. Just create new instance and register media hotkeys with it. It implements same api as other providers

final GnomeMediaProvider provider = new GnomeMediaProvider("test");
provider.register(MediaKey.MEDIA_STOP, new HotKeyListener() {...});

however, this requires extra native libraries. You will need to have your users install

# apt-get install libunixsocket-java

then, if you get UnsatisfiedLinkError, you will need to find where libunix-java.so is located and add this path as -Djava.library.path=$YOUR_PATH. It's usually /usr/lib/jni or /usr/local/lib/jni

Clojure

If you are interested in nicer api from clojure, check out a wrapper library developed by Stian Håklev: https://github.com/houshuang/keymaster-clj

Feedback

I would really appreciate it if you could test the library and post some bug reports. I've tested on Win 7, Win XP, Ubuntu 10.10 and 11.04. I've tested Mac OSX code only in 32-bit virtual machine, and a bit on a real 64-bit machine. So feedback is greatly appreciated, especially from people who have real Mac with real Apple keyboard, BSD users, people with some advanced keyboards, and just anybody who wants to help.

jkeymaster's People

Contributors

tulskiy avatar mauris avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.