How to suppress F keys of other aplications

痞子三分冷 提交于 2020-05-09 07:04:14

问题


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());

来源:https://stackoverflow.com/questions/61274722/how-to-suppress-f-keys-of-other-aplications

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!