Page 1 of 1

Posted: Wed Feb 28, 2007 9:05 pm
by netmaestro
Is it that you want to do two different things based on single or double click and you don't want the single click to register if it's actually a double click? If that's the case, here's a method to accomplish it. There is a downside: your reaction to a single click is slowed down by waiting to see if it's going to change to a doubleclick. In my example I've speeded up the wait to 2/3 of the user's doubleclick rate to make it a bit snappier for single click events:

Code: Select all

 CreateImage(0,64,64,32)
 OpenWindow(0, 0, 0, 200, 105, "ImageGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) 
 CreateGadgetList(WindowID(0))
 ImageGadget(1, 60, 10, 100, 83, ImageID(0), #PB_Image_Border)     

 Repeat 
  ev = WaitWindowEvent()
  Select ev 
    Case  #PB_Event_Gadget
      gadget = EventGadget()
      Select EventType()
        Case #PB_EventType_LeftClick
          detectedevent = #PB_EventType_LeftClick ; Start with single click but don't report yet
          ;
          ; Enter wait state to see if it'll change to a doubleclick event
          start = ElapsedMilliseconds()
          Repeat
            tmp = WaitWindowEvent(1)
            If tmp = #PB_Event_Gadget And EventGadget() = gadget 
              If EventType() = #PB_EventType_LeftDoubleClick
                detectedevent = #PB_EventType_LeftDoubleClick
                Break ; Got the changed event, no need to keep waiting
              EndIf
            EndIf
          Until ElapsedMilliseconds()-start >= GetDoubleClickTime_()/3*2
          ;
          Debug detectedevent ; 0=single, 2=double
   EndSelect
 EndSelect
 Until ev = #PB_Event_CloseWindow

Posted: Wed Feb 28, 2007 10:01 pm
by netmaestro
Also just found a similar solution with a different method by the mighty srod here:

http://www.purebasic.fr/english/viewtop ... 41&start=7