Code: Select all
Debug ElapsedMilliseconds( )
; result window = 0
; result macos = 830
Code: Select all
Debug ElapsedMilliseconds( )
; result window = 0
; result macos = 830
Code: Select all
Static ClickTime.q, ClickCount
Protected DoubleClickTime
;CompilerIf #PB_Compiler_OS = #PB_OS_Windows
; DoubleClickTime = 10
;CompilerElse
DoubleClickTime = DoubleClickTime( )
;CompilerEndIf
If ClickTime And
DoubleClickTime > ( ElapsedMilliseconds( ) - ClickTime )
ClickCount + 1
Else
ClickCount = 1
EndIf
ClickTime = ElapsedMilliseconds( )
I already posted the link to the documentation for ElapsedMilliseconds().
Code: Select all
#DoubleClickTime = 500
Structure MouseButton_Structure
Pressed.i
ReleaseTime.i
EndStructure
Global Dim MouseButtonArray.MouseButton_Structure(3)
Procedure.i IsMouseDoubleClick(MouseButton.i)
Protected Result.i
If MouseButtonArray(MouseButton)\Pressed
If MouseButton(MouseButton) = 0
MouseButtonArray(MouseButton)\Pressed = #False
MouseTime = ElapsedMilliseconds()
If MouseButtonArray(MouseButton)\ReleaseTime > -1
If MouseButtonArray(MouseButton)\ReleaseTime + #DoubleClickTime > MouseTime
Result = #True
EndIf
EndIf
MouseButtonArray(MouseButton)\ReleaseTime = MouseTime
EndIf
Else
If MouseButton(MouseButton)
MouseButtonArray(MouseButton)\Pressed = #True
EndIf
EndIf
ProcedureReturn Result
EndProcedure
MouseButtonArray(#PB_MouseButton_Left)\ReleaseTime = -1
MouseButtonArray(#PB_MouseButton_Right)\ReleaseTime = -1
MouseButtonArray(#PB_MouseButton_Middle)\ReleaseTime = -1
InitSprite()
InitMouse()
InitKeyboard()
OpenWindow(0, 0, 0, 220, 160, "Press ESC to end", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 0, 0, 220, 160)
Repeat
Repeat
Event = WindowEvent()
Select Event
Case #PB_Event_CloseWindow
End
EndSelect
Until Event = 0
FlipBuffers()
ClearScreen(RGB(0, 0, 0))
ExamineMouse()
If IsMouseDoubleClick(#PB_MouseButton_Left)
Debug "DoubleClick"
EndIf
ExamineKeyboard()
If KeyboardReleased(#PB_Key_Escape)
End
EndIf
Delay(1)
ForEver
Code: Select all
Procedure MouseState( )
Static press.b, ClickTime.q, ClickCount
Protected DoubleClickTime, state.b
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Linux
Protected desktop_x, desktop_y, handle, *GdkWindow.GdkWindowObject = gdk_window_at_pointer_( @desktop_x, @desktop_y )
If *GdkWindow
gdk_window_get_pointer_(*GdkWindow, @desktop_x, @desktop_y, @mask)
EndIf
If mask & 256; #GDK_BUTTON1_MASK
state = 1
EndIf
If mask & 512 ; #GDK_BUTTON3_MASK
state = 3
EndIf
If mask & 1024 ; #GDK_BUTTON2_MASK
state = 2
EndIf
CompilerCase #PB_OS_Windows
state = GetAsyncKeyState_(#VK_LBUTTON) >> 15 & 1 +
GetAsyncKeyState_(#VK_RBUTTON) >> 15 & 2 +
GetAsyncKeyState_(#VK_MBUTTON) >> 15 & 3
CompilerCase #PB_OS_MacOS
state = CocoaMessage(0, 0, "NSEvent pressedMouseButtons")
CompilerEndSelect
If press <> state
If state
If DoubleClickTime( ) > ( ElapsedMilliseconds( ) - ClickTime )
ClickCount + 1
Else
ClickCount = 1
EndIf
ClickTime = ElapsedMilliseconds( )
If ClickCount = 1
If state = 1
Debug "LeftDown - "
ElseIf state = 2
Debug "RightDown - "
EndIf
EndIf
Else
If ClickCount = 1
If press = 1
Debug "LeftUp - "
ElseIf press = 2
Debug "RightUp - "
EndIf
EndIf
;\\ do 3click events
If ClickCount = 3
If press = 1
Debug " Left3Click - "
ElseIf press = 2
Debug " Right3Click - "
EndIf
;\\ do 2click events
ElseIf ClickCount = 2
If press = 1
Debug " Left2Click - "
ElseIf press = 2
Debug " Right2Click - "
EndIf
;\\ do 1click events
Else
; If Not PressedWidget( )\state\drag
; If PressedWidget( ) = EnteredWidget( )
If press = 1
Debug " LeftClick - "
ElseIf press = 2
Debug " RightClick - "
EndIf
; EndIf
; EndIf
EndIf
EndIf
press = state
EndIf
EndProcedure
OpenWindow(0, 0, 0, 220, 160, "Press ESC to end", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
Repeat
Event = WaitWindowEvent()
MouseState( )
Until Event = #PB_Event_CloseWindow
A single click resulte inLeftDown -
LeftUp -
LeftClick -
Left2Click -
Only if I start with a double click it fails once.LeftDown -
LeftUp -
LeftClick -
LeftDown -
Code: Select all
1click
LeftDown -
LeftUp -
LeftClick -
2click
LeftDown -
LeftUp -
LeftClick -
Left2Click -
3click
LeftDown -
LeftUp -
LeftClick -
Left2Click -
Left3Click -
4>=click
LeftDown -
LeftUp -
LeftClick -
Left2Click -
Left3Click -
LeftClick -
LeftClick -
LeftClick -
LeftClick -
LeftClick -
Sorry I looped this native function DoubleClickTime().
Code: Select all
state = GetAsyncKeyState_(#VK_LBUTTON) >> 15 & 1 +
GetAsyncKeyState_(#VK_RBUTTON) >> 15 & 2 +
GetAsyncKeyState_(#VK_MBUTTON) >> 15 & 3
Code: Select all
state = (GetAsyncKeyState_(#VK_LBUTTON) >> 16 & 1) |
2*(GetAsyncKeyState_(#VK_RBUTTON) >> 16 & 1) |
3*(GetAsyncKeyState_(#VK_MBUTTON) >> 16 & 1)
Code: Select all
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
DoubleClickTime = 10
CompilerElse
DoubleClickTime = DoubleClickTime( )
CompilerEndIf
Code: Select all
DoubleClickTime = DoubleClickTime( )
For what? On windows it doesn't work that way.Olli wrote: ↑Sun Feb 05, 2023 10:23 am You should just type this :Code: Select all
DoubleClickTime = DoubleClickTime( )
If you are sure about this bug :mestnyi wrote: ↑Sun Feb 05, 2023 7:41 pmFor what? On windows it doesn't work that way.Olli wrote: ↑Sun Feb 05, 2023 10:23 am You should just type this :Code: Select all
DoubleClickTime = DoubleClickTime( )
Code: Select all
DoubleClickTime = 300