Hopefully just a quick question on windows.
trying to use the mousewheel with the canvas gadget. Is it possible to set the keyboard focus on the gadget programmatically to allow mousewheel data to be read without having to click on the gadget on a windows system?
regards
cd
CanvasGadget events
-
- Addict
- Posts: 1310
- Joined: Fri Aug 28, 2015 6:10 pm
- Location: Portugal
CanvasGadget events
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
Re: CanvasGadget events
Yes; just call the SetActiveGadget() function on the canvas in question.collectordave wrote:Is it possible to set the keyboard focus on the gadget programmatically to allow mousewheel data to be read without having to click on the gadget on a windows system?

Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel 

Re: CanvasGadget events
Sure, create it with #PB_Canvas_Keyboard and later call SetActiveGadget().
You can even steal keyboard focus on the MouseEnter event, and "give it back" to the previous activegadget on the MouseLeave event.
You can even steal keyboard focus on the MouseEnter event, and "give it back" to the previous activegadget on the MouseLeave event.
-
- Addict
- Posts: 1310
- Joined: Fri Aug 28, 2015 6:10 pm
- Location: Portugal
Re: CanvasGadget events
Thanks TI-994A and kenmo
Works like a charm.
Handing back the focus using -1 as the gadget is that correct?
Cheers
cd
Works like a charm.
Handing back the focus using -1 as the gadget is that correct?
Cheers
cd
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
Re: CanvasGadget events
Do I miss something ?
#PB_EventType_MouseWheel does not need SetActiveGadget()
#PB_EventType_MouseWheel does not need SetActiveGadget()
Code: Select all
Procedure SizeWindowHandler()
ResizeGadget(1,10,10,WindowWidth(0)-20,WindowHeight(0)-20)
EndProcedure
LoadImage(0, #PB_Compiler_Home + "examples/Sources/Data/PureBasicLogo.bmp")
If OpenWindow(0, 0, 0, 400, 300, "CanvasGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered |#PB_Window_SizeGadget)
CanvasGadget(1, 10, 10, 200, 200)
StringGadget(2,220,10,100,20,"TEST")
;BindEvent( #PB_Event_SizeWindow,@SizeWindowHandler())
y = 100
SetActiveGadget(2)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Quit = 1
Case #PB_Event_Gadget
Select EventGadget()
Case 1
Select EventType()
; Case #PB_EventType_MouseMove
; x = GetGadgetAttribute(1,#PB_Canvas_MouseX)
; y = GetGadgetAttribute(1,#PB_Canvas_MouseY)
;
Case #PB_EventType_MouseWheel
delta = GetGadgetAttribute(1, #PB_Canvas_WheelDelta )
StartVectorDrawing(CanvasVectorOutput(1))
VectorSourceColor($FFFFFFFF)
FillVectorOutput()
y = y+delta
MovePathCursor(10,y)
DrawVectorImage(ImageID(0),255,180,30)
StopVectorDrawing()
EndSelect
EndSelect
EndSelect
Until Quit = 1
EndIf
Egypt my love
-
- Addict
- Posts: 1310
- Joined: Fri Aug 28, 2015 6:10 pm
- Location: Portugal
Re: CanvasGadget events
Hi RASHAD
I was working on this quote from the help file
Added a debug line afte the Case #PB_EventType_MouseWheel eventtype and still nothing.
Creating the canvas with #PB_Canvas_Keyboard it works after clicking in the gadget.
You can then add the setactive gadget after eventgadget to set the focus on the gadget and it works immediatly.
Cheers
cd
I was working on this quote from the help file
Tried your code and nothing happens when i use the mouse wheel on windows 7.On Windows, the #PB_EventType_MouseWheel event is also only reported if the gadget has keyboard focus. On the other OS, this event is reported to the gadget under the cursor, regardless of keyboard focus.
Added a debug line afte the Case #PB_EventType_MouseWheel eventtype and still nothing.
Creating the canvas with #PB_Canvas_Keyboard it works after clicking in the gadget.
You can then add the setactive gadget after eventgadget to set the focus on the gadget and it works immediatly.
Cheers
cd
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.