Here's another way using keyboard shortcuts that generate menu events:
Code: Select all
#w_main = 0 ;window
#event_selectedShortcut = 100 ;event
#My_Shortcut_Colon = 186 + #PB_Shortcut_Shift ;constant obtained from Shortcut gadget test
OpenWindow(#w_main,0,0,200,200,"colon pushed")
AddKeyboardShortcut(#w_main, #My_Shortcut_Colon, #event_selectedShortcut)
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_Menu
If EventMenu() = #event_selectedShortcut
Debug "pressed [:]"
EndIf
Case #PB_Event_CloseWindow
End
EndSelect
ForEver
The only unusual part of this is that the shortcut value is not listed in the help manual with other constants but it was obtained by using the ShortcutGadget() to generate the value by pushing the desired key combination (Shift+;).
The following code shows how this was done:
Code: Select all
#g_ShortcutSelect = 0 ;gadget
#w_main = 0 ;window
;#My_Shortcut_SemiColon = 186 ;constant obtained from Shortcut gadget test
OpenWindow(#w_main,0,0,200,200,"colon pushed")
ShortcutGadget(#g_ShortcutSelect,10,10,180,40,0)
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_Gadget
currentShortcut = GetGadgetState(0)
Debug "value of shortcut selected:" + currentShortcut
Case #PB_Event_CloseWindow
End
EndSelect
ForEver
I made these tests using a Windows 11 OS.