In my program want to have a text field that will contain the current keys pressed by the user. I can do this with JNativeHook, but the problem currently is that JNativeHook is registering tons of key presses when it is held down. Is there a way to ignore key holds? I would like to simply append to the text field whatever keys are currently held without overpopulating it with duplicates
Here is the relevant part of my code: (This is in my main class that extends Application and implements NativeKeyListener)
@Override
public void nativeKeyPressed(NativeKeyEvent e) {
System.out.print(NativeKeyEvent.getKeyText(e.getKeyCode()) + " + ");
if (e.getKeyText(e.getKeyCode()) == "F6")
System.out.println("F6");
}
@Override
public void nativeKeyReleased(NativeKeyEvent e) {
try {
GlobalScreen.unregisterNativeHook();
} catch (NativeHookException ex) {}
}
@Override
public void nativeKeyTyped(NativeKeyEvent e) {
}
All of this works fine, but if I hold a key, it will spam that key code in the console. Can I stop this?