JWindow closes after a particular key combination
Hi again.
I can't seem to find on how to get my key combination functioning well.
The key combination I want to happen is " (Left)Ctrl + (Left)Shift + 'a' "
Here's my code for you to better solve this thread.
Thanks.
Code:
import java.awt.Dimension;
import java.awt.Window;
import java.awt.Toolkit;
import javax.swing.JOptionPane;
import javax.swing.JWindow;
import javax.swing.JFrame;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
public class Application {
private JFrame frame = new JFrame("Test");
private Window window = new Window(frame);
private Dimension resolution = Toolkit.getDefaultToolkit().getScreenSize();
private JWindow application = new JWindow(window);
public Application() {
application.addKeyListener(new keyListener());
application.setAlwaysOnTop(true);
application.setSize(resolution);
application.setVisible(true);
}
private class keyListener implements KeyListener {
public void keyPressed(KeyEvent event) {
int key = event.getModifiersEx();
System.out.println(key);
if(key == 192) {
int option = JOptionPane.showConfirmDialog(null, "Do you wish to exit?", "Confirmation", JOptionPane.YES_NO_OPTION);
if(option==0) System.exit(0);
}
}
public void keyReleased(KeyEvent event) {
}
public void keyTyped(KeyEvent e) {
}
}
public static void main(String[] args){
new Application();
}
}