Win32 Mouse Input?

Started by
8 comments, last by Metus 22 years, 4 months ago
Hi! My current code goes like this LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { case WM_LMOUSEDOWN { if(bLeftMouseDown) bLeftMouseDown = false; else bLeftMouseDown = true; }break; } If the mouse is pressed and being HOLD when the next frame is processed (and WM_LMOUSEDOWN is sent), shouldn''t that set the bLeftMouseDOwn become false then? My problem is that when i press and HOLD the left mouse, i doesn''t need to press the button to activate the WM_LMOUSEDOWN
Ethereal
Advertisement
I''m not sure what you''re trying to do, but you might want to try handling the WM_LBUTTONDOWN message instead of WM_LMOUSEDOWN(?).

==========================================In a team, you either lead, follow or GET OUT OF THE WAY.
quote:Original post by Metus
  if(bLeftMouseDown)   bLeftMouseDown = false;  else   bLeftMouseDown = true;  

If bLeftMouseDown == true, set to false; if bLeftMouseDown == false, set to true. Looks like inversion to me. Do this instead:
bLeftMouseDown = !bLeftMouseDown;  


[Edit:] forgot to close quote tags.

Edited by - Oluseyi on November 14, 2001 6:17:53 PM
First of all, there''s no WM_LMOUSEDOWN! I believe you wanted to say WM_LBUTTONDOWN instead... anyways... the thing with WM_LBUTTONDOWN is that the message is sent only ONCE (even if you hold down the mouse button) and when you release the left mouse button a WM_LBUTTONUP is sent.. so in any case you don''t need the bLeftMouseDown = !bLeftMouseDown code... in order to do what you want to gotta process both WM_LBUTTONDOWN and WM_LBUTTONUP....your code is gonna look something like this:

case WM_LBUTTONDOWN:  {  bLeftMouseDown = TRUE;  } break;case WM_LBUTTONUP:  {  bLeftMouseDOwn = FALSE;  } break; 


Hope this helps...
If you need to find whether the mouse button is being held down at any given time, use:

GetAsyncKeyState(VK_LBUTTON);

[Edit]: Sorry, Gladiator - your method's better, just didn't se it

---------------

I finally got it all together...
...and then forgot where I put it.

Edited by - AdmiralBinary on November 14, 2001 8:13:12 PM
Binary, True, that''s another way to do it which gives you immediate value of the left mouse button

It''s basically the same as the key checking technique...you can have a key buffer of 256 BOOLs and assign TRUE/FALSE when processing WM_KEYDOWN/WM_KEYUP, but at the same time you can use GetAsyncKeyState() to do the same for the particular key you are looking for

The only difference is that with WM_LBUTTONDOWN/WM_LBUTTONUP is you save a few cycles which are used for calling the function each time through the loop... wheres the MESSAGE way assigns a couple values only ONCE per mouse button key press/release.. which makes a LITTLE faster ;-)

Well anyways... the difference is hardly noticable so you can use either method... its up to you to decide

later
One more thing.. if you want to find out whether the left mouse button is down every time the mouse is moved, you''d use the GetAsyncKeyState() like follows:

case WM_MOUSEMOVE:
{

bLeftMouseDown = GetAsyncKeyState(VK_LBUTTON);

} break;

lata

case WM_LBUTTONDOWN:
{
bLeftMouseDown = TRUE;
}break;
case WM_LBUTTONUP:
{
bLeftMouseDown = FALSE;
}break;


My code looks just like this now, but the same thing happens.
Each time the Callback is being processed, it seems that the WM_LBUTTONDOWN is being sent when i PRESS and HOLD the Left Mouse Button (I can exit by app with HOLDING the mouse button and MOVE it over my Exit Button [My designed gui])

Later today / tonight i will post my code on my page so you can look at it in whole!

Edited by - Metus on November 15, 2001 3:12:07 AM
Ethereal
quote:Original post by Metus
...it seems that the WM_LBUTTONDOWN is being sent when i PRESS and HOLD the Left Mouse Button...

The WM_LBUTTONDOWN message is sent whenever the left mouse button is pressed, but WM_LBUTTONUP is sent as soon as it is released. Your problem is that you break after handling the message, leaving the DefWindowProc() to handle it again. Here''s some corrected code:
...case WM_LBUTTONDOWN:  bLeftMouseDown = TRUE;  return 0;case WM_LBUTTONUP:  bLeftMouseDown = FALSE;  return 0;... 

quote:Later today / tonight i will post my code on my page so you can look at it in whole!

Please, don''t. Reading through large amounts of someone else''s code is a chore; don''t subject us to that. Post the relevant portions only.
Sorry for the inactivity, but I've got my source and exe up at This place
I would appreciate if you could solve this problem for me

Edited by - Metus on November 27, 2001 2:54:12 PM

Edited by - Metus on November 27, 2001 2:54:57 PM
Ethereal

This topic is closed to new replies.

Advertisement