I created a Java application that uses GlobalScreen
to addNativeKeyListener
. (jnativehook library)
When i press F5 it executes a code. Problem is that if i give focus to other applications it also executes funciton for the focused application. (for example Chrome will refreshes website)
Is there a way to suppress these functions and give my application full control over F5?
I use this to listen for F5 keyPress globaly (even if my application loses focus):
public class Listen implements NativeKeyListener {
@Override
public void nativeKeyReleased(NativeKeyEvent arg0) {
if (arg0.getKeyCode() == NativeKeyEvent.VC_F5) {
Main.executeCode();
}
}
}
And from my main i have to call:
try {
GlobalScreen.registerNativeHook();
}
catch (NativeHookException ex){
}
GlobalScreen.addNativeKeyListener(new Listen());