FB II Compiler

PG PRO

Debugging

Memory

System

Mathematics

Resources

Disk I/O

Windows

Controls

Menus

Mouse

Keyboard

Text

Fonts

Drawing

Sound

Clipboard

Printing

Communication

ASM

Made with FB

MOUSE

Handle double and triple clicks


I need my program to respond to single mouse clicks, double mouse clicks and triple mouse clicks, and do different things accordingly. Naively, I made the following structure:


LOCAL FN doMouse
  mouseevent = MOUSE(0)
  SELECT ABS(mouseevent)
    CASE _click1 : FN HandleSingleClick
    CASE _click2 : FN HandleDoubleClick
    CASE _click3 : FN HandleTripleClick
  END SELECT
END FN

However, this doesn't work because, before I can get my double or triple clicks in, a single click is detected and FN HandleSingleClick is called. Is there a way to handle this?


Some more reading (it was actually right in front of my eyes) showed that the expected behavior of:

SELECT mousevent
  case _click1 : FN HandleSingleClick
  case _click2 : FN HandleDoubleClick
  case _click3 : FN HandleTripleClick
END SELECT

is, in fact, that _click1 is reported first, then _click2, then _click3. So a triple click will call handlesingleclick, handledoubleclick AND handletripleclick. My question then becomes is there a way to call HandleDoubleClick without calling HandleSingleClick?

{My motivation for this is that I'm writing an application to be usuable with a remote mouse. The more functionality I can build into the remote mouse, i.e. the more functions the mouse can do, the better.}

Jeff Schwartz


Since you want to test for triple-clicks (and possibly more), your best bet is to do it like it is done in low-level languages.

Store the time (TickCount) and position (GetMouse) of the click in globals _each time a mousedown is detected_.

That done, whenever the mouse is clicked, you can determine if it is a double-click by testing to see if the following conditions are met:

1) current TickCount <= (globalTicks + [DblTime])
2) current mousepos is within 5 pixels of globalpos in each direction

If both of those tests pass, the click is a double-click.

To test for a triple-click would require an additional set of globals, using the same tests.

David Blache


In your mousedown routine you need something like this :

LastTime&=When&:' and save the last time we used it
'
What it does is gets the time that the user clicked the mouse. If they clicked it twice within the time period set in the MOUSE control panel (double click speed), they you handle it different. I use LastTime& as a global.

I'll leave it up to someone to supply the refinements for triple clicks (I've never used them because I think they are a little to confusing).

Mel Patrick


Not unless your computer is psychic. When you receive the first click, how do you know you aren't going to receive a second or third?

This is why in normal Mac user interfaces, the double and triple click actions are a superset of the single click. For example, in the Finder, a sing le click selects a file, a double click selects a file and then opens it. In some word processors, a single click selects an insertion point, a double-click selects a word, and a triple-click selects a paragraph. So it doesn't matter if the single-click routine gets called, then the double click, then the tripl click routine.

That said, after receiving the first click, you *could* set a global and wait the _dblClick time (via idle events). If a second click doesn't come in by then, you can then call your single click routine. If a second click comes in, you then need to set another global to wait for a potential third click...

Greg