Check if mouse button is pressed?
-
Hi. I'm porting an application from Macintosh to Windows, and at some point the function StillDown() is used. I can't seem to find a way to figure out whether the mouse button is pressed on Windows... Is there a function for that?
-
Hi. I'm porting an application from Macintosh to Windows, and at some point the function StillDown() is used. I can't seem to find a way to figure out whether the mouse button is pressed on Windows... Is there a function for that?
Check out the
WM_LBUTTONDOWN
andWM_LBUTTONUP
messages.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
-
Check out the
WM_LBUTTONDOWN
andWM_LBUTTONUP
messages.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
Yea, that's what I do now. I set up a boolean at mouse down, and mouse up the boolean is set to false. The problem is, however, when the mouse is down some sort of a drag operation is started. The StillDown function on the mac is used in a while loop, I tried to do the same for windows, but of course that ends up being an endless loop...
-
Yea, that's what I do now. I set up a boolean at mouse down, and mouse up the boolean is set to false. The problem is, however, when the mouse is down some sort of a drag operation is started. The StillDown function on the mac is used in a while loop, I tried to do the same for windows, but of course that ends up being an endless loop...
Capture the mouse on the first
WM_LBUTTONDOWN
, then handleWM_MOUSEMOVE
, checking thewParam
. Be sure to release capture onWM_LBUTTONUP
or when your app loses focus! WM_MOUSEMOVE fwKeys = wParam; // key flags xPos = LOWORD(lParam); // horizontal position of cursor yPos = HIWORD(lParam); // vertical position of cursor ParametersfwKeys
Value ofwParam
. Indicates whether various virtual keys are down. This parameter can be any combination of the following values: MK_CONTROL Set if the ctrl key is down. MK_LBUTTON Set if the left mouse button is down. MK_MBUTTON Set if the middle mouse button is down. MK_RBUTTON Set if the right mouse button is down. MK_SHIFT Set if the shift key is down. /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.com -
Capture the mouse on the first
WM_LBUTTONDOWN
, then handleWM_MOUSEMOVE
, checking thewParam
. Be sure to release capture onWM_LBUTTONUP
or when your app loses focus! WM_MOUSEMOVE fwKeys = wParam; // key flags xPos = LOWORD(lParam); // horizontal position of cursor yPos = HIWORD(lParam); // vertical position of cursor ParametersfwKeys
Value ofwParam
. Indicates whether various virtual keys are down. This parameter can be any combination of the following values: MK_CONTROL Set if the ctrl key is down. MK_LBUTTON Set if the left mouse button is down. MK_MBUTTON Set if the middle mouse button is down. MK_RBUTTON Set if the right mouse button is down. MK_SHIFT Set if the shift key is down. /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.comI found what I was looking for. Apparently, GetAsyncKeyState (found in the keyboard section of MSDN) can also query whether the mouse button is down, which was exactly what I was looking for. Thanks anyway :)
-
I found what I was looking for. Apparently, GetAsyncKeyState (found in the keyboard section of MSDN) can also query whether the mouse button is down, which was exactly what I was looking for. Thanks anyway :)
Ah, much easier! :) /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.com
-
I found what I was looking for. Apparently, GetAsyncKeyState (found in the keyboard section of MSDN) can also query whether the mouse button is down, which was exactly what I was looking for. Thanks anyway :)
Under several circumstances that will fail. The only reliable way of tracking when the mouse button is released is by capturing in on the down message. One failure point is if you have an overlapping window or the user very quickly drags the mouse to another application. Anyone who thinks he has a better idea of what's good for people than people do is a swine. - P.J. O'Rourke
-
Under several circumstances that will fail. The only reliable way of tracking when the mouse button is released is by capturing in on the down message. One failure point is if you have an overlapping window or the user very quickly drags the mouse to another application. Anyone who thinks he has a better idea of what's good for people than people do is a swine. - P.J. O'Rourke
Not quite sure what ya mean. It seems to work fine here when I drag the mouse out of the window? And I don't see how overlapping windows could occur?
-
Not quite sure what ya mean. It seems to work fine here when I drag the mouse out of the window? And I don't see how overlapping windows could occur?
Windows is message driven so using a loop to monitor where the mouse is is self-defeating. You incur a performance penalty for no reason. If you simply need to know when a mouse leaves a window, use TrackMouseEvent with the TME_LEAVE option. If you are monitoring the mouse with the button down, the prescribed method is to use mouse capture so that the mouse message will be sent to that window. As for overlapping windows; this is windows. Unless you have taken over the screen, there are all sorts of overlapping windows present. Your app is guaranteed to receive mouse messages only if you are capturing the mouse with the button down. (What if an other app pops up over the window which you are monitoring?) Anyone who thinks he has a better idea of what's good for people than people do is a swine. - P.J. O'Rourke