[SDL] Double Click
Peter Ketting
peterketting at sysmatrix.net
Sat May 5 21:55:47 PDT 2007
> Do you know if there is an easy way to detect double click,
> instead of just down or up?
Check events, etc...
if (event == MOUSE_BUTTONDOWN)
{
if (IsDoubleClick == TRUE)
{
...
/* Double click detected. */
}
}
Check Double Click;
BOOL IsDoubleClick (void)
{
static ULONG LastClickTicks;
ULONG CurrentClickTicks;
/* First time this function is called, LastClickTicks
has not been initialised yet. */
if (! LastClickTicks)
{
LastClickTicks = SDL_GetTicks ();
return (FALSE);
}
else
{
CurrentClickTicks = SDL_GetTicks ();
/* If the period between the two clicks is smaller
or equal to a pre-defined number, we report a
DoubleClick event. */
if (CurrentClickTicks - LastClickTicks <= MAX_TICKS)
{
/* Update LastClickTicks and signal a DoubleClick. */
LastClickTicks = CurrentClickTicks;
return (TRUE);
}
/* Update LastClickTicks and signal a SingleClick. */
LastClickTicks - CurrentClickTicks;
return (FALSE);
}
}
Not tested, but this is how I would do it.
Cheers,
Peter
More information about the SDL
mailing list