An option for the Tab key is to use AddKeyboardShortcut. I think Window's default tab handling might prevent the CanvasGadget from detecting it.
#PB_Canvas_Modifiers returns a bitwise value, so it might not be exactly equal to #PB_Canvas_Shift or #PB_Canvas_Control. Use the bitwise AND (&) operator to check if one is held down. I'm unsure why Control doesn't seem to work with #PB_Canvas_Input.
Code: Select all
Procedure OnGainFocus()
AddKeyboardShortcut(0, #PB_Shortcut_Tab, 0)
EndProcedure
Procedure OnLostFocus()
RemoveKeyboardShortcut(0, #PB_Shortcut_Tab)
EndProcedure
Procedure OnMenuEvent()
Select EventMenu()
Case 0
Debug "Tab"
EndSelect
EndProcedure
Procedure OnKeyDown()
Define char = GetGadgetAttribute(0, #PB_Canvas_Key)
If GetGadgetAttribute(0, #PB_Canvas_Modifiers) & #PB_Canvas_Shift
Debug "Key Down Shift"
EndIf
If GetGadgetAttribute(0, #PB_Canvas_Modifiers) & #PB_Canvas_Control
Debug "Key Down Control"
EndIf
Debug "Raw key: " + char
EndProcedure
Procedure OnInput()
Define char$ = Chr(GetGadgetAttribute(0, #PB_Canvas_Input))
If GetGadgetAttribute(0, #PB_Canvas_Modifiers) & #PB_Canvas_Shift
Debug "Input Shift"
EndIf
If GetGadgetAttribute(0, #PB_Canvas_Modifiers) & #PB_Canvas_Control
Debug "Input Control"
EndIf
Debug "Input: " + char$
EndProcedure
OpenWindow(0, 0, 0, 500, 500, "", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
CanvasGadget(0, 0, 0, 500, 500, #PB_Canvas_Keyboard | #PB_Canvas_DrawFocus)
SetActiveGadget(0)
BindGadgetEvent(0, @OnKeyDown(), #PB_EventType_KeyDown)
BindGadgetEvent(0, @OnInput(), #PB_EventType_Input)
BindGadgetEvent(0, @OnGainFocus(), #PB_EventType_Focus)
BindGadgetEvent(0, @OnGainFocus(), #PB_EventType_LostFocus)
BindEvent(#PB_Event_Menu, @OnMenuEvent())
PostEvent(#PB_Event_Gadget, 0, 0, #PB_EventType_Focus)
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow