dotfiles/.config/Code/User/History/22e92be3/5yQh.java
RafayAhmad7548 ab03d5f10c test
2024-06-16 18:53:25 +05:00

54 lines
No EOL
1.3 KiB
Java

package com.rutils;
import org.jnativehook.GlobalScreen;
import org.jnativehook.NativeHookException;
import org.jnativehook.keyboard.NativeKeyEvent;
import org.jnativehook.keyboard.NativeKeyListener;
public class GlobalKeyListener implements NativeKeyListener{
public void nativeKeyPressed(NativeKeyEvent e){
if(e.getKeyCode() == NativeKeyEvent.VC_SHIFT){
ProcessBuilder builder = new ProcessBuilder("hello");
}
}
public void nativeKeyReleased(NativeKeyEvent e){}
public void nativeKeyTyped(NativeKeyEvent e){}
GlobalKeyListener(){
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(this);
try{
Thread.sleep(500);
}
catch(InterruptedException e){
e.printStackTrace();
}
GlobalScreen.removeNativeKeyListener(this);
try{
GlobalScreen.unregisterNativeHook();
}
catch(NativeHookException e){
e.printStackTrace();
}
}
public static void main(String[] args){
new GlobalKeyListener();
}
}