CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2008
    Posts
    61

    [RESOLVED] Trap right-click + control using masks

    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. @.@

    Code:
    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.
    Code:
    				if(e.isControlDown() && e.isMetaDown())
    				{
    					JOptionPane.showMessageDialog(null, "I'll be more polite");
    				}
    Thank you.
    Last edited by Emerald214; October 28th, 2009 at 03:31 PM.

  2. #2
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: Trap right-click + control using masks

    Quote Originally Posted by Emerald214 View Post
    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
    Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured