Both #PB_Event_LeftClick and #PB_Event_LeftDoubleClick in EventLoop

Just starting out? Need help? Post your questions and find answers here.
User avatar
crossroads
New User
New User
Posts: 9
Joined: Sat Apr 10, 2004 10:17 pm
Location: Rhine Main Area - Germany

Both #PB_Event_LeftClick and #PB_Event_LeftDoubleClick in EventLoop

Post 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?
My very first BASIC Program is Open Source now:
10 PRINT "HELLO WORLD !"
20 END
RUN
User avatar
mk-soft
Always Here
Always Here
Posts: 6206
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Both #PB_Event_LeftClick and #PB_Event_LeftDoubleClick in EventLoop

Post 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.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
crossroads
New User
New User
Posts: 9
Joined: Sat Apr 10, 2004 10:17 pm
Location: Rhine Main Area - Germany

Re: Both #PB_Event_LeftClick and #PB_Event_LeftDoubleClick in EventLoop

Post 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:
My very first BASIC Program is Open Source now:
10 PRINT "HELLO WORLD !"
20 END
RUN
User avatar
mk-soft
Always Here
Always Here
Posts: 6206
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Both #PB_Event_LeftClick and #PB_Event_LeftDoubleClick in EventLoop

Post 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.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
BarryG
Addict
Addict
Posts: 4128
Joined: Thu Apr 18, 2019 8:17 am

Re: Both #PB_Event_LeftClick and #PB_Event_LeftDoubleClick in EventLoop

Post 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.
Post Reply