How do I detect if both left and right buttons are pushed?

Posted by Greg McGuffey on Stack Overflow See other posts from Stack Overflow or by Greg McGuffey
Published on 2009-07-25T19:53:50Z Indexed on 2010/04/27 16:53 UTC
Read the original article Hit count: 299

Filed under:
|

I would like have three mouse actions over a control: left, right and BOTH.

I've got the left and right and am currently using the middle button for the third, but am curious how I could use the left and right buttons being pressed together, for those situations where the user has a mouse without a middle button. This would be handled in the OnMouseDown method of a custom control.

UPDATE After reviewing the suggested answers, I need to clarify that what I was attempting to do was to take action on the mouse click in the MouseDown event (actually OnMouseDown method of a control). Because it appears that .NET will always raise two MouseDown events when both the left and right buttons on the mouse are clicked (one for each button), I'm guessing the only way to do this would be either do some low level windows message management or to implement some sort of delayed execution of an action after MouseDown. In the end, it is just way simpler to use the middle mouse button.

Now, if the action took place on MouseUp, then Gary's or nos's suggestions would work well.

Any further insights on this problem would be appreciated. Thanks!

© Stack Overflow or respective owner

Related posts about .NET

Related posts about mouse