Detecting gadget focus when Tabbing to it
Posted: Wed Feb 17, 2021 3:30 pm
Hi all, having a mental blank here and can't work this out... all I want to do is make each button have an asterisk put on it when I press the Tab key (not mouse click!) to give it the focus.
But this code doesn't work, and there's no #PB_Event_GadgetFocus event... so how would I do this? Thanks.
See last code below for my hack solution.
This also doesn't work:
I've done the below for now, but surely there's a better/cleaner/non-hack way?
But this code doesn't work, and there's no #PB_Event_GadgetFocus event... so how would I do this? Thanks.
See last code below for my hack solution.
Code: Select all
If OpenWindow(0, 200, 200, 270, 100, "Press Tab a few times", #PB_Window_SystemMenu)
ButtonGadget(1, 10, 10, 250, 21, "")
ButtonGadget(2, 10, 40, 250, 21, "")
ButtonGadget(3, 10, 70, 250, 21, "")
SetActiveGadget(1)
Repeat
ev=WaitWindowEvent()
If ev=#PB_Event_Gadget
SetGadgetText(EventGadget(),"*")
EndIf
Until ev = #PB_Event_CloseWindow
EndIf
Code: Select all
If OpenWindow(0, 200, 200, 270, 100, "Press Tab a few times", #PB_Window_SystemMenu)
ButtonGadget(1, 10, 10, 250, 21, "")
ButtonGadget(2, 10, 40, 250, 21, "")
ButtonGadget(3, 10, 70, 250, 21, "")
SetActiveGadget(1)
Repeat
ev=WaitWindowEvent()
If ev=#PB_Event_Gadget
If EventType()=#PB_EventType_Focus
SetGadgetText(EventGadget(),"*")
EndIf
EndIf
Until ev = #PB_Event_CloseWindow
EndIf
Code: Select all
If OpenWindow(0, 200, 200, 270, 100, "Press Tab a few times", #PB_Window_SystemMenu)
ButtonGadget(1, 10, 10, 250, 21, "")
ButtonGadget(2, 10, 40, 250, 21, "")
ButtonGadget(3, 10, 70, 250, 21, "")
Repeat
ev=WaitWindowEvent()
newfocus=GetActiveGadget()
If newfocus<>-1 And newfocus<>oldfocus
oldfocus=newfocus
SetGadgetText(newfocus,"*")
EndIf
Until ev = #PB_Event_CloseWindow
EndIf