2

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!

TheAppService
  • 133
  • 1
  • 1
  • 12

1 Answers1

5

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

}
TheAppService
  • 133
  • 1
  • 1
  • 12
  • what are those numbers means? – gumuruh Jan 14 '23 at 14:02
  • 1
    If you look at this class: https://github.com/kwhat/jnativehook/blob/2.2/src/main/java/com/github/kwhat/jnativehook/keyboard/NativeKeyEvent.java You can see, that these numbers represent the properties of a specific keyboard key. If you want to determine the numbers for a specific key on you keyboard, have a look at inspecting them with this listener: https://github.com/kwhat/jnativehook/blob/2.2/doc/Keyboard.md – TheAppService Jan 14 '23 at 20:42