Jump to content
  • Advertisement
Sign in to follow this  
svetpet

[Direct Input] Detect single click

This topic is 2842 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

Hello. I need function or algorythm or whatever to detect if one of the mouse buttons is clicked once and not to detect if the mbutton is still pressed. I.e. i really dont need the check if it is still pressed like DirectINput do now i want to check if it is clicked once. I need this for my dialogue system. If someone help me i will be very gratefull and buy him beer :)

Share this post


Link to post
Share on other sites
Advertisement
0 views nice. Nevermind in case someone is wondering how to acheive single click detection here is one solution:

if( label->isMouseDown(tr->nodes[j]->label))
{
__int64 cntsPerSec = 0;
//evaluate how much counts are in second;for instance 2987294 counts for one second
QueryPerformanceFrequency((LARGE_INTEGER*)&cntsPerSec);
//evaluates how much seconds for one count; for instance 1/40 or 0.025
float secsPerCnt = 1.0f / (float)cntsPerSec;

__int64 prevTimeStamp = 0;
//takes the prev time in counts
QueryPerformanceCounter((LARGE_INTEGER*)&prevTimeStamp);

__int64 currTimeStamp = 0;
//takes the current time in counts
QueryPerformanceCounter((LARGE_INTEGER*)&currTimeStamp);
//convert the counts into seconds
float dt = (currTimeStamp - prevTimeStamp)*secsPerCnt;
}


Immediatelly after you check for mouse down start timer and save its value in variable and after that save in another variable the new timer value. The result is simulation of single click which takes like 0.1 second and this solved my problem.

Share this post


Link to post
Share on other sites
Seems I'm to late and you already solve it yourself, anyways here's how I did it:



// true if button is pressed
bool DirectInput::mouseButtonPressed(int button)
{
// mLastMouseState is the state of the mouse in previous frame
return (!mLastMouseState.rgbButtons[button] && mMouseState.rgbButtons[button] & 0x80) != 0;
}

Share this post


Link to post
Share on other sites
It should be noted that for anything other than joystick input Direct Input isn't recommended, not even my MS.

Instead you should be using the Windows message system and react to the incoming events to keep a track of what is going on.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!