Just starting out? Need help? Post your questions and find answers here.
Joubarbe
Enthusiast
Posts: 713 Joined: Wed Sep 18, 2013 11:54 am
Location: France
Post
by Joubarbe » Fri May 23, 2025 9:34 am
Code: Select all
OpenWindow(0, 0, 0, 500, 500, "", #PB_Window_ScreenCentered)
CanvasGadget(0, 0, 0, 500, 500)
SetActiveGadget(0)
Procedure DisplayMouseX()
Debug GetGadgetAttribute(0, #PB_Canvas_MouseX)
; Debug WindowMouseX(0) ; Works fine.
EndProcedure
BindEvent(#PB_Event_Timer, @DisplayMouseX())
BindEvent(#PB_Event_Menu, @DisplayMouseX())
AddWindowTimer(0, 0, 1000)
AddKeyboardShortcut(0, #PB_Shortcut_Space, 0)
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
Hmm?
SPH
Enthusiast
Posts: 572 Joined: Tue Jan 04, 2011 6:21 pm
Post
by SPH » Fri May 23, 2025 9:45 am
Only a lot of "0"
!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Portable LENOVO ideapad 110-17ACL 64 bits
Version de PB : 6.12LTS - 64 bits
pjay
Enthusiast
Posts: 253 Joined: Thu Mar 30, 2006 11:14 am
Post
by pjay » Fri May 23, 2025 9:56 am
The MouseX / MouseY attributes should be funneled through the MouseMove event:
Code: Select all
OpenWindow(0, 0, 0, 500, 500, "", #PB_Window_ScreenCentered)
CanvasGadget(0, 0, 0, 500, 500)
SetActiveGadget(0)
Procedure DisplayMouseX()
Debug GetGadgetAttribute(0, #PB_Canvas_MouseX)
EndProcedure
BindEvent(#PB_Event_Gadget, @DisplayMouseX(), 0, 0, #PB_EventType_MouseMove)
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
RASHAD
PureBasic Expert
Posts: 4954 Joined: Sun Apr 12, 2009 6:27 am
Post
by RASHAD » Fri May 23, 2025 10:13 am
Hi
Maybe 3 or more ways to get the canvas gadget mouse positions
But you lost your way
Code: Select all
OpenWindow(0, 0, 0, 500, 500, "", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
CanvasGadget(0, 0, 0, 500, 500)
SetActiveGadget(0)
Procedure DisplayMouseX()
Debug GetGadgetAttribute(0,#PB_Canvas_MouseX)
;Debug WindowMouseX(0) ; Works fine.
EndProcedure
;AddWindowTimer(0, 0, 10)
;BindEvent(#PB_Event_Timer, @DisplayMouseX())
BindEvent(#PB_Event_Gadget, @DisplayMouseX())
AddKeyboardShortcut(0, #PB_Shortcut_Space, 0)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Quit = 1
; Case #PB_Event_Gadget
; Select EventGadget()
; Case 0
; Select EventType()
; Case #PB_EventType_MouseMove
; x = GetGadgetAttribute(0,#PB_Canvas_MouseX)
; y = GetGadgetAttribute(0,#PB_Canvas_MouseY)
; Debug x
; Debug y
; EndSelect
; EndSelect
EndSelect
Until Quit = 1
Egypt my love
Axolotl
Addict
Posts: 838 Joined: Wed Dec 31, 2008 3:36 pm
Post
by Axolotl » Fri May 23, 2025 10:28 am
Joubarbe wrote: Fri May 23, 2025 9:34 am
.....
Hmm?
Well, just one F1 on
and a little down scrolling will show you a working example.
Online CanvasGadget Documentation
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home . Now started with Linux (VM: Ubuntu 22.04 ).
Joubarbe
Enthusiast
Posts: 713 Joined: Wed Sep 18, 2013 11:54 am
Location: France
Post
by Joubarbe » Fri May 23, 2025 11:08 am
Okay, sorry then!
My example was quite bad, I was trying to reproduce a situation in my main project where, sometimes, I couldn't get the mouse position. Although I realise now that it only works through the gadget event, and what I was trying to do is to get it when another event was triggered (returned 0).