I\'m currently trying to create a little remote-app for Android to control a MediaPlayer (like Rythmbox) on my PC.
Most media-players understand the special keys on
VK_MEDIA_PLAY_PAUSE
VK_VOLUME_MUTE
VK_VOLUME_DOWN
VK_MEDIA_NEXT_TRACK
VK_MEDIA_PREV_TRACK
Control a Windows apps using Java
To temporarily solve your problem just google "rhythmbox android remote." There are some great projects already.
Have you already tried to send the OS dependent key codes to the Robot
? The multimedia keys are unfortunately not directly supported in Java yet, not even in Java 1.7 but most of the keycode definitions in java.awt.event.KeyCode
have the same value as their native Windows pendants. The Robot doesn't filter unknown key codes directly in Java but lets its native back end decide what to do with them. So there is a chance that it might work at least on certain platforms.
The MUTE key code would be 0xAD
. Here is a list of the Windows Key Codes.
So, I think it's not possible to do this with pure Java. I tried something else to find out which key-code the special keys have, but this small program only returns 0
for those keys (it works for "normal" keys):
public class GetKeycode implements KeyListener{
private JFrame f;
private JLabel feld;
public GetKeycode(){
f = new JFrame("GetKeycode");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.addKeyListener(this);
feld = new JLabel();
f.add(feld);
f.pack();
f.setVisible(true);
}
@Override
public void keyReleased(KeyEvent e) {
feld.setText(e.getKeyCode()+"");
}
public static void main(String[] args) {
new GetKeycode();
}
// Unused:
@Override public void keyPressed(KeyEvent e) {}
@Override public void keyTyped(KeyEvent arg0) {}
}
I hope this will be implemented in future versions of the JRE. But at the moment, there seems to be no solution for this.
Thanks for all the answers anyways.