JNativeHook Post a native key event

早过忘川 提交于 2019-12-24 10:10:23

问题


I tried to post a new native key pressing to the system using the java library https://github.com/kwhat/jnativehook. The method

GlobalScreen.postNativeEvent();

Needs to get passed a NativeInputEvent object, which needs the Parameters

  • An instance of Global Screen
  • Two integers and one long

Based on the documentation I can't figure out what the required parameters are and how to for example initialize a new GlobalScreen object. (https://github.com/kwhat/jnativehook/blob/master/src/java/org/jnativehook/NativeInputEvent.java)

Thanks for answers in advance!


回答1:


With the help of the developer I solved the question. To post media key events to the system using jnativehook you can use the following code:

public static void MediaKeyForward(){
    GlobalScreen.postNativeEvent(new NativeKeyEvent(2401,0,176,57369,org.jnativehook.keyboard.NativeKeyEvent.CHAR_UNDEFINED));

}
public static void MediaKeyBack(){
    GlobalScreen.postNativeEvent(new NativeKeyEvent(2401,0,177,57360,org.jnativehook.keyboard.NativeKeyEvent.CHAR_UNDEFINED));

}
public static void MediaKeyPause(){
 GlobalScreen.postNativeEvent(new NativeKeyEvent(2401,0,179,57378,org.jnativehook.keyboard.NativeKeyEvent.CHAR_UNDEFINED));

}


来源:https://stackoverflow.com/questions/43821047/jnativehook-post-a-native-key-event

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