Page 1 of 1
Problem with mouse button up
Posted: Sun Jun 09, 2024 11:14 am
by coco2
Found this today. When you click on a window and hold the button down, then move the mouse outside the window and release it will give a button up event on Windows and Mac. There is no event on Linux. Bug? Or no bug? In my application I definitely need that mouse button up event otherwise strange things happen.
Code: Select all
; You can click inside the window and drag outside the window and release the button
; The button release should trigger an event but it doesn't in Linux
OpenWindow(0, 0, 0, 420, 420, "Test Mouse Button Down/Up", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget |
#PB_Window_MaximizeGadget | #PB_Window_ScreenCentered | #PB_Window_SizeGadget)
CanvasGadget(0, 0, 0, 420, 420, #PB_Canvas_Container)
CloseGadgetList()
Repeat
event = WaitWindowEvent(10)
If event = #PB_Event_Gadget
eventType = EventType()
If eventType = #PB_EventType_LeftButtonDown
Debug "Mouse left button down"
EndIf
If eventType = #PB_EventType_LeftButtonUp
Debug "Mouse left button up"
EndIf
EndIf
Until event = #PB_Event_CloseWindow
Re: Problem with mouse button up
Posted: Sun Jun 09, 2024 12:59 pm
by mk-soft
Unfortunately, you cannot query the mouse yourself via g_signal_connect, as the CanvasGadget does not allow any further processing.
Should be adapted from Fred that mouse up also comes through outside of the gadget.
Re: Problem with mouse button up
Posted: Sun Jun 09, 2024 2:14 pm
by mk-soft
Solution:
Evaluate all events yourself. Should work with all gadgets.
Update v1.02
Code: Select all
;-TOP my mk-soft
CompilerIf #PB_Compiler_OS = #PB_OS_Linux
CompilerIf Defined(GdkEvent,#PB_Structure)=#False
Structure GdkEvent
StructureUnion
Type.l
any.GdkEventAny
expose.GdkEventExpose
no_expose.GdkEventNoExpose
visibility.GdkEventVisibility
motion.GdkEventMotion
button.GdkEventButton
scroll.GdkEventScroll
key.GdkEventKey
crossing.GdkEventCrossing
focus_change.GdkEventFocus
configure.GdkEventConfigure
property.GdkEventProperty
selection.GdkEventSelection
proximity.GdkEventProximity
client.GdkEventClient
dnd.GdkEventDND
window_state.GdkEventWindowState
setting.GdkEventSetting
EndStructureUnion
EndStructure
CompilerEndIf
; ----
ProcedureC _signal_event_cb(*Widget, *Event.GdkEvent, Gadget)
With *Event
Select \Type
Case #GDK_BUTTON_PRESS
Select \button\button
Case 1
;Debug "Left Button Press"
PostEvent(#PB_Event_Gadget, EventWindow(), Gadget, #PB_EventType_LeftButtonDown)
Case 2
;Debug "Right Button Press"
PostEvent(#PB_Event_Gadget, EventWindow(), Gadget, #PB_EventType_MiddleButtonDown)
Case 3
;Debug "Right Button Press"
PostEvent(#PB_Event_Gadget, EventWindow(), Gadget, #PB_EventType_RightButtonDown)
EndSelect
ProcedureReturn #True
Case #GDK_BUTTON_RELEASE
Select \button\button
Case 1
;Debug "Left Button Release"
PostEvent(#PB_Event_Gadget, EventWindow(), Gadget, #PB_EventType_LeftButtonUp)
Case 2
;Debug "Right Button Release"
PostEvent(#PB_Event_Gadget, EventWindow(), Gadget, #PB_EventType_MiddleButtonUp)
Case 3
;Debug "Right Button Release"
PostEvent(#PB_Event_Gadget, EventWindow(), Gadget, #PB_EventType_RightButtonUp)
EndSelect
ProcedureReturn #True
EndSelect
EndWith
ProcedureReturn #False
EndProcedure
CompilerEndIf
; ********
OpenWindow(0, 0, 0, 420, 420, "Test Mouse Button Down/Up", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget |
#PB_Window_MaximizeGadget | #PB_Window_ScreenCentered | #PB_Window_SizeGadget)
CanvasGadget(0, 0, 0, 420, 420, #PB_Canvas_Container)
CloseGadgetList()
signal_event_handler = g_signal_connect_(GadgetID(0), "event", @_signal_event_cb(), 0) ; <= UserData = Gadget Number
Repeat
event = WaitWindowEvent(10)
If event = #PB_Event_Gadget
Select EventType()
Case #PB_EventType_LeftButtonDown
Debug "Mouse left button down"
Case #PB_EventType_LeftButtonUp
Debug "Mouse left button up"
EndSelect
EndIf
Until event = #PB_Event_CloseWindow
Re: Problem with mouse button up
Posted: Sun Jun 09, 2024 8:50 pm
by tft
I always use this for testing. If something new comes along, I'll expand it. Maybe it helps
Code: Select all
;{ Main Loop
#PB_MouseWheele = 522
#PB_MouseWheeleUp = 4287102976
#PB_MouseWheeleDown = 7864320
Global LastKeyDown
Global LastKeyUp
Global LastChar.s
Global KeyDown
Global KeyUp
Global st.POINT ; System Mouse Position
Dim KeyStatus.i(256)
Repeat
;{ Event & KeyState
KeyDown = 0
KeyUp = 0
Repeat
LastKeyDown = 0
LastKeyUp = 0
LastChar = ""
; Always process all the events to flush the queue at every frame
Event = WindowEvent()
If EventWindow() = #MainWindow
Select Event
Case #WM_MOUSEMOVE
;PrintN("MouseMove")
Case #WM_MOUSEHWHEEL
;PrintN("MouseWheelButton ("+Str(#WM_MOUSEHWHEEL)+")")
Case #WM_MOUSELEAVE
;PrintN("MouseLeve ("+Str(#WM_MOUSELEAVE)+")")
Case #WM_TIMER
;PrintN("Timer")
Case #WM_PAINT
;PrintN("Paint")
Case 13115
;PrintN("UnkNow")
Case 13111
;PrintN("UnkNow")
Case 13112
;PrintN("UnkNow")
Case 13113
;PrintN("UnkNow")
Case 13114
;PrintN("UnkNow")
Case 13104
;PrintN("WindowInFront (13104)")
Case 96
;PrintN("UnkNow")
Case 519
;PrintN("MouseWheelButtonDown")
Case 520
;PrintN("MouseWheelButtonUp")
Case #PB_MouseWheele
Select EventwParam()
Case #PB_MouseWheeleDown
;PrintN("MouseWheel Down")
Case #PB_MouseWheeleUp
;PrintN("MouseWheel Up")
EndSelect
Case #WM_NCMOUSEMOVE
;PrintN("NC_MouseMove ("+Str(#WM_NCMOUSEMOVE)+")")
Case #WM_LBUTTONDOWN
;PrintN("LeftMouseButtonDown ("+Str(#WM_LBUTTONDOWN)+")")
Case #WM_LBUTTONUP
;PrintN("LeftMouseButtonUp ("+Str(#WM_LBUTTONUP)+")")
Case #WM_RBUTTONDOWN
;PrintN("RightMouseButtonDown ("+Str(#WM_RBUTTONDOWN)+")")
Case #WM_RBUTTONUP
;PrintN("RightMouseButtonUp ("+Str(#WM_RBUTTONUP)+")")
Case #WM_LBUTTONDBLCLK
;PrintN("LeftMouseButtonDobbleKlick ("+Str(#WM_LBUTTONDBLCLK)+")")
Case #WM_RBUTTONDBLCLK
;PrintN("RightMouseButtonDobbleKlick ("+Str(#WM_RBUTTONDBLCLK)+")")
Case #WM_KEYUP
;PrintN("KeywUp "+Str(#WM_KEYDOWN ))
Select EventwParam()
Case #ESC ; Programm beenden bei drücken der ESC Taste
Quit = 1
Case 16
;PrintN("ShiftPressed "+Str(16 ))
Case 17
;PrintN("CTRLPressed "+Str(17 ))
Case 91
;PrintN("WindowPressed "+Str(91 ))
Case 8
;PrintN("Backspace "+Str(8 ))
Case 9
;PrintN("Tab "+Str(9 ))
Case 20
;PrintN("caps lock"+Str(20 ))
Case 13
;PrintN("enter"+Str(13 ))
Default
;PrintN(Str(EventwParam()))
EndSelect
LastKeyUp = EventwParam()
Case #WM_CHAR
;PrintN("Char "+Chr(EventwParam())+"/"+Str(EventwParam()))
LastChar.s = Chr(EventwParam())
Case #WM_KEYDOWN
;PrintN("KeywDown "+Str(#WM_KEYDOWN ))
Select EventwParam()
Case #ESC ; Programm beenden bei drücken der ESC Taste
Quit = 1
Case 16
;PrintN("ShiftPressed "+Str(16 ))
Case 17
;PrintN("CTRLPressed "+Str(17 ))
Case 91
;PrintN("WindowPressed "+Str(91 ))
Case 8
;PrintN("Backspace "+Str(8 ))
Case 9
;PrintN("Tab "+Str(9 ))
Case 20
;PrintN("caps lock"+Str(20 ))
Case 13
;PrintN("enter"+Str(13 ))
Default
;PrintN(Str(EventwParam()))
EndSelect
LastKeyDown = EventwParam()
Case 260
;PrintN("AltPressed "+Str(260 ))
Case 261
;PrintN("AltReleased "+Str(261 ))
Case #PB_Event_CloseWindow
Quit = 1
Case #PB_Event_Gadget
; Do the normal application management here
Define Gadget = EventGadget()
Select Gadget
Case 1
PlaySound(blib(3))
Quit = Exit()
SetActiveWindow(#MainWindow)
Case 2
PlaySound(blib(3))
Case 3
PlaySound(blib(3))
Case 4
PlaySound(blib(3))
EndSelect
Default
If Event<>0
;PrintN(Str(Event))
EndIf
EndSelect
Else
EndIf
If LastKeyDown > 0
;PrintN(Chr(LastKeyDown)+"("+Str(1)+")")
KeyStatus(LastKeyDown) = 1
KeyDown = KeyDown+1
EndIf
If LastKeyUp > 0
;PrintN(Chr(LastKeyUp)+"("+Str(0)+")")
KeyStatus(LastKeyUp) = 0
KeyUp = KeyUp+1
EndIf
Until Event = 0 ; Quit the event loop only when no more events are available
If KeyDown > 0 Or KeyUp > 0
Define t.s = Str(KeyStatus(Asc("W")))+"|"+Str(KeyStatus(Asc("A")))+"|"+Str(KeyStatus(Asc("S")))+"|"+Str(KeyStatus(Asc("D")))
PrintN(t)
EndIf
; Hinterlegt in der st.POINT Strukture die aktuelle MousePosition
GetCursorPos_(st.POINT)
; Ermittelt den actuellen Tastendruck, unabhängig ob das Fenster Aktiv ist oder nicht. In diesem falle die Linke CTRL Taste
If (GetAsyncKeyState_(#VK_LCONTROL) & $8000)
;Debug "Pressed Left Ctrl "+Str(#VK_LCONTROL)
EndIf
;}
Until Quit = 1
;}
TFT
Re: Problem with mouse button up
Posted: Sun Jun 09, 2024 11:05 pm
by coco2
Thanks mk-soft, I have applied the fix to my application.
Hi tft, I couldn't run it, maybe something missing?
Re: Problem with mouse button up
Posted: Tue Jun 11, 2024 9:24 am
by coco2