| Re: processing mouse dbl-clicks in IDL? [message #8703 is a reply to message #8702] |
Fri, 18 April 1997 00:00   |
davidf
Messages: 2866 Registered: September 1996
|
Senior Member |
|
|
Paul van Delst <paulv@airs2.ssec.wisc.edu> writes:
> I was wondering if anyone had code or hints on how to process *double*
> clicks on a mouse button within an IDL event handler? How would you wait
> to check for the same event (a particular mouse button click) to reoccur
> within a (user/default) specified time interval?
>
> I looked in the IDL FAQ and various links off of it but didn't find
> anything.
Well, here is a piece of code that can reliably detect a double
click on a BUTTON widget, at least on my Mac and Windows NT machines.
I wrote this off the top of my head. I haven't tried to put this
into a real piece of code, so I don't know if it will be generally
useful. (My personal feeling is that I would test any code with
this kind of button stategy VERY carefully before I showed it to
anyone important!)
Here is how it works. The first button click sets a "first" flag
and sends a TIMER event to the button. If a SECOND button click event
gets to the event handler BEFORE the TIMER event does, then this
is a DOUBLE CLICK event! A timer delay of 0.1 second works
perfectly on my Mac. I need a delay of 0.2 seconds on
my (much faster) Windows NT machine.
Let me know how this works in a real piece of code. :-)
Cheers!
David
************************************************************ ***
PRO MOUSE_EVENT,event
WIDGET_CONTROL, event.top, /DESTROY
END
PRO DOUBLE_MOUSE_CLICK, event
WIDGET_CONTROL, event.top, GET_UVALUE=info, /NO_COPY
thisEvent = TAG_NAMES(event, /Structure)
; Double click event.
IF (thisEvent EQ 'WIDGET_BUTTON') AND (info.first EQ 1) THEN BEGIN
Print, 'Hooray, DOUBLE click!'
info.first = 0
WIDGET_CONTROL, event.top, SET_UVALUE=info, /NO_COPY
RETURN
ENDIF
; Initial click event.
IF (thisEvent EQ 'WIDGET_BUTTON') AND (info.first EQ 0) THEN BEGIN
info.first = 1
WIDGET_CONTROL, event.id, Timer=info.delay
ENDIF
; Single click event.
IF (thisEvent EQ 'WIDGET_TIMER') AND (info.first EQ 1) THEN BEGIN
Print, 'No, that was a SINGLE click!'
info.first = 0
ENDIF
WIDGET_CONTROL, event.top, SET_UVALUE=info, /NO_COPY
END
PRO MOUSE, delay
IF N_PARAMS() EQ 0 THEN delay = 0.1
info = {first:0, delay:delay}
tlb = WIDGET_BASE(COLUMN=1)
button = WIDGET_BUTTON(tlb, Value='Double Click Me...', $
EVENT_PRO='DOUBLE_MOUSE_CLICK')
quit = WIDGET_BUTTON(tlb, Value='Quit')
WIDGET_CONTROL, tlb, /REALIZE, SET_UVALUE=info, /NO_COPY
XMANAGER, 'mouse', tlb
END
************************************************************ ***
-----------------------------------------------------------
David Fanning, Ph.D.
Fanning Software Consulting
2642 Bradbury Court, Fort Collins, CO 80521
Phone: 970-221-0438 Fax: 970-221-4762
E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com
-----------------------------------------------------------
|
|
|
|