Sign in to follow this  

[input question]How to get a 'mouse click' ?

This topic is 4860 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi! So far i only know how to get normal mouse input using win32 API. like:
GetAsyncKeyState(VK_LBUTTON) & 0x8000f
with that i can tell whether the left mouse button is being pressed at specific time. But thats not enough, i want my program to notify me when the player clicks with the mouse. that 'click' includes two actions: press down the mouse button & release it. how can i do it? thx!

Share this post


Link to post
Share on other sites
Hello !

You have 2 solutions :

1) polling. In your game loop, you get the button state. When you detect that the state is PUSHED and if the previous state was not PUSHED then you can fire a CLICK event.

2) using windows message : add a handler to WM_LBUTTONDOWN or WM_RBUTTONDOWN. See the msdn for furtehr informations.

HTH;

Share this post


Link to post
Share on other sites
Quote:
Original post by Emmanuel Deloget
1) polling. In your game loop, you get the button state. When you detect that the state is PUSHED and if the previous state was not PUSHED then you can fire a CLICK event.


Are u sure it works? i tried but failed, my program is like this:

bool IsLMBClicked()
{
static bool bLastState = false; // record whether the button was pressed last time
// ( previous state )
if( GetAsyncKeyState(VK_LBUTTON) & 0x8000f )
{
bLastState = true;
}
if( !(GetAsyncKeyState(VK_LBUTTON) & 0x8000f) && bLastState )
{
// we can be sure about that now.
bLastState = false;
return true;
}
return false;
}




when executed, it seems that snippet can't fire a CLICK event.

Share this post


Link to post
Share on other sites
Depends on how you call it. I see you call it IsLBClicked() but maybe it is IsLBReleased().

Here's an edit:
int	CheckLB()
{
static int bLastState = 0;

if( GetAsyncKeyState(VK_LBUTTON) & 0x8000f )
{
bLastState = 1;
return 1;
}
else if( bLastState == 1 )
{
bLastState = 0; // No need to keep record
return 2; // Return release
}
return 0;
}

Share this post


Link to post
Share on other sites

This topic is 4860 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this