Page 1 of 1

Both #PB_Event_LeftClick and #PB_Event_LeftDoubleClick in EventLoop

Posted: Sat Aug 20, 2022 10:49 am
by crossroads

Code: Select all

; PureBasic 6.00 LTS (x86)
; Windows 11 21H2 (Build 22000.856)

OpenWindow(0,0,0,300,300,"test")

Repeat
  Event = WaitWindowEvent()
  Select Event
    Case #PB_Event_LeftDoubleClick:Debug "double"
    Case #PB_Event_LeftClick:Debug "single"
  EndSelect
Until Event = #PB_Event_CloseWindow
What it should do:
=> a singe left mouse click should display "single" in debugger window (this part is fine)
=> a double left click should only display "double" - but it doesn't :shock:
Instead this three messages are displayed: "single", "double" and "single" again. :(

What's wrong with this code?

Re: Both #PB_Event_LeftClick and #PB_Event_LeftDoubleClick in EventLoop

Posted: Sat Aug 20, 2022 3:16 pm
by mk-soft
The OS always delivers the (single) click in order not to have a delay in the double click timeout. If the mouse is clicked twice within the double-click time, the double-click event is sent in addition to the single click.

Re: Both #PB_Event_LeftClick and #PB_Event_LeftDoubleClick in EventLoop

Posted: Sat Aug 20, 2022 5:19 pm
by crossroads
mk-soft wrote: Sat Aug 20, 2022 3:16 pm The OS always delivers the (single) click in order not to have a delay in the double click timeout. If the mouse is clicked twice within the double-click time, the double-click event is sent in addition to the single click.
It seems I have to set up a callback routine to handle these mouse events. I'll give it a try :wink:

Re: Both #PB_Event_LeftClick and #PB_Event_LeftDoubleClick in EventLoop

Posted: Sat Aug 20, 2022 6:08 pm
by mk-soft
The events only arrive at the main window when there is no gadget in the way.
Each gadget has its own EventType and some also support the double-click event.
Furthermore, see the CanvasGadget for creating your own gadgets.

Re: Both #PB_Event_LeftClick and #PB_Event_LeftDoubleClick in EventLoop

Posted: Sun Aug 21, 2022 12:29 am
by BarryG
A double-click can't be done without a single click, by its very nature. You'd need to count how many clicks occur in the double-click timeout period, but that means a single click will have a slight delay before it's accepted as a single-click. There's no way around this, because in OP's case you can't read the user's mind and know how many clicks they intend (even for gadgets that support #PB_EventType_LeftDoubleClick). IMO, it's better and easier just to use a key qualifier or something, so that a click on its own means do A, but a click with Ctrl held down means do B.