So I'm trying to "log" keys that are being pressed. The problem is when I run my code, the program just auto stops and sends me back to where I can code.
I use Eclipse
import org.jnativehook.keyboard.NativeKeyEvent;
import org.jnativehook.keyboard.NativeKeyListener;
public class Listener implements NativeKeyListener {
public static void main(String[] args) {
System.out.print("Program started");
}
@Override
public void nativeKeyPressed(NativeKeyEvent arg0) {
System.out.print("A key was pressed");
}
@Override
public void nativeKeyReleased(NativeKeyEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void nativeKeyTyped(NativeKeyEvent arg0) {
// TODO Auto-generated method stub
}
}
You need to add the listener to the GlobalScreen object and keep the program running.