How can I emulate pressing media keys in Java? Such as play/pause, next/previous, volume control.
C# has VK_MEDIA_PLAY_PAUSE, VK_MEDIA_NEXT_TRACK
You can achieve it with https://github.com/kwhat/jnativehook and afterwards spy on the keys. In my question I've written some sample methods:
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));
}
Everything to do is to include the library into your project. A sample of how to spy on keys and get the neccesary Parameters to create a key event can be found here.