This commit is contained in:
RafayAhmad7548 2024-06-16 18:53:25 +05:00
parent 37776af5db
commit ab03d5f10c
4045 changed files with 286212 additions and 3 deletions

View file

@ -0,0 +1,38 @@
package com.rutils;
import org.jnativehook.GlobalScreen;
import org.jnativehook.keyboard.NativeKeyEvent;
import org.jnativehook.keyboard.NativeKeyListener;
public class GlobalKeyListenerExample implements NativeKeyListener {
public void nativeKeyPressed(NativeKeyEvent e) {
if (e.getKeyCode() == NativeKeyEvent.VC_SHIFT) {
System.out.println("Shift key pressed");
}
}
public void nativeKeyReleased(NativeKeyEvent e) { }
public void nativeKeyTyped(NativeKeyEvent e) { }
public static void main(String[] args) {
try {
GlobalScreen.registerNativeHook();
}
catch (Exception ex) {
System.err.println("There was a problem registering the native hook.");
System.err.println(ex.getMessage());
System.exit(1);
}
GlobalScreen.addNativeKeyListener(new GlobalKeyListenerExample());
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
GlobalScreen.shutdown();
}
}