Click to See Complete Forum and Search --> : [RESOLVED] Trap right-click + control using masks


Emerald214
October 28th, 2009, 03:27 PM
How to trap right-click + control using masks? I tried but it doesn't work. If I replace BUTTON3_DOWN_MASK with BUTTON1_DOWN_MASK or BUTTON2_DOWN_MASK, it works. Why? I don't understand. @.@


public class FrameTest extends JFrame {
public FrameTest()
{
setSize(500, 500);
setLocation(300, 200);
setVisible(true);
setFocusable(true);

addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent e) {
int mask = MouseEvent.CTRL_DOWN_MASK | MouseEvent.BUTTON3_DOWN_MASK;
if((e.getModifiersEx() & mask) == mask)
{
JOptionPane.showMessageDialog(null, "I'll be more polite");
}
}
});
}

public static void main(String[] args) {
FrameTest app = new FrameTest();
app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}


I tried like this, it also didn't work. :(

if(e.isControlDown() && e.isMetaDown())
{
JOptionPane.showMessageDialog(null, "I'll be more polite");
}


Thank you.

dlorde
October 29th, 2009, 06:25 AM
How to trap right-click + control using masks? I tried but it doesn't work. If I replace BUTTON3_DOWN_MASK with BUTTON1_DOWN_MASK or BUTTON2_DOWN_MASK, it works. Why? I don't understand. @.@
The both versions you posted work fine here. Maybe your mouse has a non-standard configuration.

To arrive at the simple is difficult...
R. Elisha