C Board  

Go Back   C Board > General Programming Boards > C# Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 12-01-2005, 12:30 PM   #1
Registered User
 
Join Date: Sep 2004
Posts: 27
Looking at current mouse button state

I have a small portion of code that I wish to bypass if the left mouse button is down. It seems a waste to use a boolean that gets set by mouse events for a single check. However, I cannot seem to find any information on how to go about just peeking at the state of the mouse buttons. Is it not possible, or is it just so simple that its never been an issue?
Lifedragn is offline   Reply With Quote
Old 12-01-2005, 12:49 PM   #2
Anti-Poster
 
Join Date: Feb 2002
Posts: 1,222
I don't think you can peek at the state of the mouse buttons. I think the mouse only transmits information when the mouse's state has changed and is incapable of responding to external queries. The events sounds like your best bet.
__________________
Rule #1: Every rule has exceptions
pianorain is offline   Reply With Quote
Old 12-01-2005, 12:53 PM   #3
Registered User
 
Join Date: Sep 2004
Posts: 27
Unfortunate, but thank you anyway.
Lifedragn is offline   Reply With Quote
Old 12-01-2005, 03:00 PM   #4
Registered User
 
Join Date: Sep 2004
Posts: 27
I just found a way to do it. For others searching for this in the future, here it is...

If you are using System.Windows.Forms, there is a Control class which contains a Static MouseButtons property. This property gets the bitwise combination representing the mouse button states.

if((Control.MouseButtons & MouseButtons.Left) == MouseButtons.Left) for example will check if the left mouse button is down.
Lifedragn is offline   Reply With Quote
Old 12-02-2005, 06:52 AM   #5
Anti-Poster
 
Join Date: Feb 2002
Posts: 1,222
Nice...good info. You might want to consider what logical operator to use. For instance, ((Control.MouseButtons & MouseButtons.Left) != 0) returns true if the left mouse button is down, but others may be also. If you want to check to see if only the left mouse button is down, you could do ((Control.MouseButtons ^ MouseButtons.Left) == 0).

However, your way works too.
__________________
Rule #1: Every rule has exceptions
pianorain is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Looking for a way to store listbox data Welder C Programming 20 11-01-2007 11:48 PM
30something GSOH seeks help with the basics of a minor programme promsan C Programming 3 05-13-2007 08:55 AM
Mouse Events disruptor108 C# Programming 0 01-23-2007 11:40 PM
compiler build error KristTlove C++ Programming 2 11-30-2003 10:16 AM
Mouse button outside of my app? BubbleMan Windows Programming 1 10-01-2001 03:33 AM


All times are GMT -6. The time now is 04:05 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22