/jwinkey

global key and mouse listener for Windows written in Java

Primary LanguageJavaApache License 2.0Apache-2.0

jwinkey


Introduction | Getting started | Troubleshooting

📚 Introduction

jwinkey is a windowless/global keyboard and mouse listener for Windows written in Java. It works by using the windows api in order to work even if the window isn't focused or hidden.

You are a Go developer? Check this out: https://github.com/daspoet/gowinkey/

📝 Getting started

To use jwinkey with Gradle or Maven, check out the documentation of jitpack [here]

Create a keyboard observer

In order to observe for keyboard interactions, you need to create a KeyStateObservable with an array of VirtualKey which contains all keys that the given observer will look for.

import dev.lukasl.jwinkey.enums.VirtualKey;
import dev.lukasl.jwinkey.observables.KeyStateObservable;

KeyStateObservable observer = KeyStateObservable.of(Arrays.asList(
    VirtualKey.VK_SHIFT,
    VirtualKey.VK_LEFT_SHIFT,
    VirtualKey.VK_RIGHT_SHIFT
));

Do on changes

After creating the observer in the step above, you can append different consumers to the observer which will be invoked once changes occur.

observer.subscribe(keyState -> {
    if (keyState.getKeyState().equals(KeyState.PRESSED))
        return;

    System.out.println("Shift released");
})