Page 1 of 1
Tab key not detected.
Posted: Wed Jun 14, 2023 11:46 am
by Pud
Help please.
Windows 10/11, PB 6.02
I need to detect the TAB key. All (?) the other keys return the key code except the TAB key. I'm sure this worked in the past.
Cheers.
Code: Select all
If OpenWindow(0, 0, 0, 220, 220, "Test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
CanvasGadget(0, 10, 10, 200, 200,#PB_Canvas_Keyboard)
Repeat
Event = WaitWindowEvent()
If Event = #PB_Event_Gadget
If EventGadget()=0
If EventType() = #PB_EventType_KeyDown
Debug GetGadgetAttribute(0,#PB_Canvas_Key)
EndIf
EndIf
EndIf
Until Event = #PB_Event_CloseWindow
EndIf
// Code Tags added (Kiffi)
Re: Tab key not detected.
Posted: Wed Jun 14, 2023 11:51 am
by BarryG
Works if you use #PB_EventType_KeyUp instead of #PB_EventType_KeyDown, so it's probably a bug. Fred?
Re: Tab key not detected.
Posted: Wed Jun 14, 2023 12:17 pm
by Axolotl
The behavior described above also applies to PB 6.03 Beta 1 on windows 10 home.
IMHO the help does not explain any restrictions here either.
Re: Tab key not detected.
Posted: Wed Jun 14, 2023 12:44 pm
by Fred
Moved for investigation
Re: Tab key not detected.
Posted: Wed Jun 14, 2023 11:53 pm
by TassyJim
The problem seems be Windows is keeping the tab key for itself to change focus.
I couldn't find a way to stop that action so I tricked Windows instead.
Create a dummy gadget with the tab order the next gadget after the canvas.
whenever the main canvas looses focus, test to see if the dummy gadget has focus.
If it does, return focus to the main canvas and act on the tab.
Code: Select all
If OpenWindow(0, 0, 0, 220, 220, "Test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
CanvasGadget(0, 10, 10, 200, 200,#PB_Canvas_Keyboard)
ButtonGadget(1,0,0,10,10,"")
Repeat
Event = WaitWindowEvent()
If Event = #PB_Event_Gadget
If EventGadget()=0
Select EventType()
Case #PB_EventType_LostFocus
If GetActiveGadget() = 1
Debug "TAB PRESSED"
SetActiveGadget(0)
EndIf
Case #PB_EventType_KeyDown
Debug GetGadgetAttribute(0,#PB_Canvas_Key)
EndSelect
EndIf
EndIf
Until Event = #PB_Event_CloseWindow
EndIf
Crude but effective.
Jim
Re: Tab key not detected.
Posted: Fri Jun 16, 2023 4:47 pm
by Mr.L
normally, to detect the tab key, you have to write this line of code after the OpenWindow command:
Code: Select all
RemoveKeyboardShortcut(0, #PB_Shortcut_Tab)
unfortunately, in the latest release (6.03 beta) it doesn't work anymore.
Re: Tab key not detected.
Posted: Sun Jul 02, 2023 9:34 am
by Fred
I tested in 5.73 and it seems the same behavior. I will check to see if I can add a flag to the CanvasGadget() to catch the TAB key as it can be useful.
Re: Tab key not detected.
Posted: Fri Sep 06, 2024 1:29 pm
by Thorium
Any news on this?
Doesn't work also when using RemoveKeyboardShortcut(0, #PB_Shortcut_Tab) after OpenWindow.
Re: Tab key not detected.
Posted: Wed Mar 05, 2025 10:39 am
by Pud
A fairly minimal workaround to get over the problem described at the start of this thread.
Code: Select all
If OpenWindow(0, 0, 0, 220, 220, "Test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
CanvasGadget(0, 10, 10, 200, 200,#PB_Canvas_Keyboard)
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_Gadget
If EventGadget()=0
Select EventType()
Case #PB_EventType_KeyDown : Debug GetGadgetAttribute(0,#PB_Canvas_Key) ;Do something
Case #PB_EventType_Focus : AddKeyboardShortcut(0,#PB_Shortcut_Tab,99)
Case #PB_EventType_LostFocus : RemoveKeyboardShortcut(0,#PB_Shortcut_Tab)
EndSelect
EndIf
Case #PB_Event_Menu
If EventMenu()=99
Debug #PB_Shortcut_Tab ;Do something
EndIf
EndSelect
Until Event = #PB_Event_CloseWindow
EndIf
Re: Tab key not detected.
Posted: Wed Mar 05, 2025 1:59 pm
by Axolotl
Or you check for the window message
WM_KEYDOWN like this .....
Code: Select all
If OpenWindow(0, 0, 0, 220, 220, "Test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
CanvasGadget(0, 10, 10, 200, 200,#PB_Canvas_Keyboard)
Repeat
Event = WaitWindowEvent()
If Event = #PB_Event_Gadget
If EventGadget()=0
If EventType() = #PB_EventType_KeyDown
Debug "Canvas: " + GetGadgetAttribute(0, #PB_Canvas_Key)
EndIf
EndIf
ElseIf Event = #WM_KEYDOWN
If GetActiveGadget() <> 0
Debug "Canvas does not have the focus. "
EndIf
If EventwParam() = #TAB
Debug "KeyDown: TAB is down "
EndIf
ElseIf Event = #WM_KEYUP
If EventwParam() = #TAB
Debug "KeyUp: TAB up again "
EndIf
EndIf
Until Event = #PB_Event_CloseWindow
EndIf