From: Tomas Wenström Date: Sun, 18 Aug 2019 17:29:24 +0000 (+0200) Subject: JNativeHook proof of concept X-Git-Url: http://git.dolda2000.com/gitweb/?a=commitdiff_plain;h=8ff7ee5a10d5524162186006c9efb91935153f2f;p=kaka%2Fcakelight.git JNativeHook proof of concept --- diff --git a/lib/jnativehook-2.1.0.jar b/lib/jnativehook-2.1.0.jar new file mode 100644 index 0000000..f9cd3b7 Binary files /dev/null and b/lib/jnativehook-2.1.0.jar differ diff --git a/src/kaka/cakelight/CakeLight.java b/src/kaka/cakelight/CakeLight.java index 3769dce..c2f896d 100644 --- a/src/kaka/cakelight/CakeLight.java +++ b/src/kaka/cakelight/CakeLight.java @@ -1,5 +1,12 @@ package kaka.cakelight; +import org.jnativehook.GlobalScreen; +import org.jnativehook.NativeHookException; +import org.jnativehook.keyboard.NativeKeyAdapter; +import org.jnativehook.keyboard.NativeKeyEvent; +import org.jnativehook.mouse.NativeMouseEvent; +import org.jnativehook.mouse.NativeMouseMotionAdapter; + public class CakeLight { private Configuration config; private Mode mode; @@ -27,6 +34,7 @@ public class CakeLight { public void startLoop() { Console.start(this, config); + initNativeHook(); // TODO // FrameGrabber grabber = FrameGrabber.from(config); // grabber.prepare(); @@ -41,6 +49,26 @@ public class CakeLight { // saveFile(data, "/home/kaka/test.img"); } + private void initNativeHook() { + try { + GlobalScreen.registerNativeHook(); + GlobalScreen.addNativeKeyListener(new NativeKeyAdapter() { + @Override + public void nativeKeyPressed(NativeKeyEvent e) { + System.out.println("key code = " + e.getKeyCode() + ", key text = '" + NativeKeyEvent.getKeyText(e.getKeyCode()) + "'"); + } + }); + GlobalScreen.addNativeMouseMotionListener(new NativeMouseMotionAdapter() { + @Override + public void nativeMouseMoved(NativeMouseEvent e) { + System.out.println("mouse point = " + e.getPoint()); + } + }); + } catch (NativeHookException e) { + e.printStackTrace(); + } + } + public void turnOff() { cleanup(); ledController.onFrame(LedFrame.from(config).fillColor(0, 0, 0));