How to detect 3 keyboard buttons in Swing?

75 views Asked by At

I want to detect if the user has pressed a combination of 3 or more keyboard buttons in Java Swing. For example, if the user has used a combination like Ctrl+Alt+R or Ctrl+Shift+Alt+R.

So far what I found over the internet is mentioned below.

public void keyTyped(KeyEvent e)<br>{<br>
    AWTKeyStroke ak = AWTKeyStroke.getAWTKeyStrokeForEvent(e);
    if(ak.equals(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_F4,InputEvent.ALT_MASK)))
    {
        System.exit(0);          
    }

But the problem with the above code is that it works fine for a combination of 2 buttons only but not for 3 or more buttons.

Please suggest a solution.

0

There are 0 answers