I'm going to make a hidden dialog in my application that get visible with a keyboard combination (e.g. Five sequent Ctrl+Shift+i).
How Can I capture keyboard combination strokes globally on the entire application?
Thanks
I'm going to make a hidden dialog in my application that get visible with a keyboard combination (e.g. Five sequent Ctrl+Shift+i).
How Can I capture keyboard combination strokes globally on the entire application?
Thanks
FullScreenTest
is an example that shows how to use Action
and Key Bindings in this context. You could substitute KeyEvent.VK_I
and the relevant KeyStroke
modifiers. Your action listener can keep count of how often it's been triggered.
I solved it by defining a DispatcherListener
:
class DispatcherListener implements KeyEventDispatcher{
private int level=0;
public boolean dispatchKeyEvent(KeyEvent e) {
if(e.getID() == KeyEvent.KEY_RELEASED){
if(e.isControlDown() && e.isShiftDown()){
if(this.level==0 && e.getKeyCode()==KeyEvent.VK_S){
level++;
}else if(this.level==1 && e.getKeyCode()==KeyEvent.VK_H){
level++;
}else if(this.level==2 && e.getKeyCode()==KeyEvent.VK_O){
level++;
}else if(this.level==3 && e.getKeyCode()==KeyEvent.VK_W){
level=0;
this.showHiddenWindow((JFrame)SwingUtilities.getRoot(e.getComponent()));
}else{
level=0;
}
//System.out.println( "level: " + level );
}
}
return false;
}
and used it as this:
KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
manager.addKeyEventDispatcher( new DispatcherListener());
Thank you all