Game Development Community

Mouse button dblclick ?

by Billy L · in Torque Game Engine · 04/23/2003 (11:45 pm) · 5 replies

Hi all !

Maybe this is a easy one !
But how do i bind a mousebutton dblclick ?

-Billy

#1
04/24/2003 (5:41 am)
I don't have the Torque code in front of me at the moment (not at my computer) however what you'll want to do is make a script function to bind to a mouse click that does something like this (psudo-code):
onClick
   if currentTime - lastCallTime < deltaClickTime
      fireDoubleClickFunction
   else
      fireClickFunction

   lastCallTime = currentTime
end
Not sure if there is a way to get current MS via script, if not you'll have to work around it like so (really a hack, I'm sure there is a better way to do this)
function clickTimerReset() {
   $clickCount = 0;
}

function mouseClickHandler() {
   $clickCount++;
   
   if( $clickCount > 1 ) {
      handleDoubleClick();
   } else {
      handleSingleClick();
   }

   schedule( deltaClickTime, clickTimerReset ); // Syntax correct? I forget now.
}
Hope that helps, again I don't have my computer at the moment so I'm a bit iffy on the syntax and such, but you get the idea.
#2
04/24/2003 (6:51 am)
Thx Pat !

I try it !
I thought the engine had a function for it !
#3
04/24/2003 (10:31 am)
A less hacked and more efficient way of doing it would be to move what Pat Wilson first said into the mouse handling code then make a bind for doubleclick for use with the scripted bind() function.

Also, it may already be in there, but missing the constant you need to bind something to it. Search for any of the other mouse constants in the source and see what you can dig up.
#4
04/24/2003 (11:25 am)
It already handles this, take a look at guiTypes.h the GuiEvent has a member variable named mouseClickCount.

When it's processing your clicks, it determines the time between clicks, if it's below some threshold value it adds your click to the mouseClickCount.

So, just use this, search for it in the engine and you'll see it is used.
#5
04/24/2003 (11:43 am)
Jared is the guiTypes.h an ingame function ?
what i want is a dblclick when i play the game like Pats idea !
But if could find the function in the source would be better .