Game Development Community

Mouse Click And Hold

by Scott Doerrfeld · in Torque Game Engine · 05/30/2007 (9:28 am) · 5 replies

I would like to differentiate between a mouse click and a mouse click-and-hold, where I can have an event happen after the mouse button is held for a certain time.

Is there a simple way to do this in the engine code?

#1
05/30/2007 (9:43 am)
There is an onMouseRepeat function in guiScrollCtrl.h that isn't quite fully setup. Trying to figure out that and it's associated vars: mNextMouseTime, mInitialMouseDelay.
#2
05/30/2007 (9:48 am)
The simplest way I can think of is implementing a high resolution timer in the engine code, exposing the object in script, and then performing the logic within Torque Script:

new TimerObject(mouseClickTimer)
{
    type = 0;
};

function responseFunction(%val))
{
        if(%val == true)
                echo("Mouse held long enough");
        else
                echo("Mouse not held long enough");
}
function leftClickAction(%val)
{
     if(%val)
     {
            mouseClickTimer.start();
     }
      else
      {
            %val = mouseClickTimer.getElapsed();
            
             if(%val > 3)  [b]// Picked an arbitrary value, 3 seconds[/b]
                   responseFunction(true);
             else
                   responseFunction(false);
      }
}

moveMap.bind(mouse, button0, leftClickAction);

The script logic is really simple, and I probably took some unnecessary logic steps, but you get the point. The high-res timer implementation is the hardest part, and that is a cake walk =).
#3
05/30/2007 (11:00 am)
How do I make a high resolution timer in the engine?
#4
05/30/2007 (11:02 am)
I was hoping I could use SI_REPEAT for the mouse click the same way it is used when a key is held down.
#5
05/30/2007 (11:12 am)
Send me an e-mail to mperry@zombieshortbus.com. I'll send you the high resolution timer I built.