I am currently developing a media application in java using the gstreamer bindings for java. All is going well except for one small issue regarding the keyboard, specifically the media keys (e.g. play/pause, back, next).
I have Actions that work fine as buttons/menu items for these functions, and was hoping to allow the use of the keys that are on some keyboards (often on laptops). However, I could not find andthing in java.awt.event.KeyEvent to represent these keys. I tried running the snippet of code below, and it worked fine for most keys, including f1-12, but did not respond to 'fn' nor to the media keys while 'fn' was held.
Does anyone know how to get these keys working?
Code:
import javax.swing.*;
import java.awt.event.*;
public class Key extends JFrame{
public Key(){
JTextField f = new JTextField(50);
f.addKeyListener(new KeyAdapter(){
public void keyPressed(KeyEvent e){
System.out.printf("%s : %d \n", e.getKeyChar(), e.getKeyCode());
}
});
setContentPane(f);
pack();
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
setVisible(true);
}
public static void main(String[] args){
new Key();
}
}