home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!gatech!darwin.sura.net!zaphod.mps.ohio-state.edu!malgudi.oar.net!hyperion!desire.wright.edu!jmatthews
- From: jmatthews@desire.wright.edu
- Newsgroups: comp.sys.mac.programmer
- Subject: Detecting double click?
- Message-ID: <1993Jan8.002831.6471@desire.wright.edu>
- Date: 8 Jan 93 00:28:31 EST
- Organization: Wright State University
- Lines: 52
-
- Recently I suggested the following way to check for double clicks:
-
- var gLastMouseUp: EventRecord;
-
- procedure SaveLastMouseUp(event: EventRecord);
- begin
- gLastMouseUp := event
- end;
-
- function CheckDoubleClick (event: EventRecord): Boolean;
- var slop: Rect;
- begin
- with gLastMouseUp.where do
- SetRect(slop, h - 2, v - 2, h + 2, v + 2);
- CheckDoubleClick:= ((event.when - gLastMouseUp.when) <=
- GetDblTime) and (PtInRect(event.where, slop))
- end;
-
- In the main event loop, call SaveLastMouseUp in response to mouseUp
- events, and call CheckDoubleClick in response to mouseDown events. The
- latter returns true when a double click (as defined in IM vol.I,
- p.260) occurs.
-
- This definition of a double click can lead to some confusion in
- subsequent calls to StillDown or WaitMouseUp. An alternative is to
- measure time between mouseDown events as follows:
-
- var gLastMouseDown: EventRecord;
- {should initialize gLastMouseDown.when to 0}
-
- function CheckDoubleClick (event: EventRecord): Boolean;
- var
- slop: Rect;
- test: Boolean;
- begin
- with gLastMouseDown.where do
- SetRect(slop, h - 2, v - 2, h + 2, v + 2);
- test := ((event.when - gLastMouseDown.when) <= GetDblTime) and
- (PtInRect(event.where, slop));
- if test then
- gLastMouseDown.when := 0 {prevent multiple clicks}
- else
- gLastMouseDown := event; {save this one for future testing}
- CheckDoubleClick := test
- end;
-
- How are others doing it?
-
- o----------------------------------------------------------------------------o
- | John B. Matthews, jmatthews@desire.wright.edu, disclaimer:= myViews <> WSU |
- | "Whom the gods would destroy, they first invite to program in C" |
- o----------------------------------------------------------------------------o
-