I'm trying to make a helper function to automatically bind menu items to keyboard shortcuts on all platforms, but it's not working. It seems to be because I have a weird confusion about variable expansion in macros. Here's my code:
Code: Select all
Macro PBShortcut(_Key) : #PB_Shortcut_#_Key : EndMacro
; Get a bitmask of #PB_Shortcut constants from a key name in the format of, e.g. Ctrl+F
Procedure GetShortcutConstant(Shortcut$)
Protected Res, I, CurKey$
For I = 1 To CountString(Shortcut$, "+") + 1
CurKey$ = LCase(StringField(Shortcut$, I, "+"))
Select CurKey$
Case "ctrl" : Res | #PB_Shortcut_Control
Case "alt" : Res | #PB_Shortcut_Alt
Case "shift" : Res | #PB_Shortcut_Shift
Default : Res | PBShortcut(CurKey$)
EndSelect
Next
ProcedureReturn Res
EndProcedure
Procedure MenuShortcutItem(ItemID, Text$)
Protected Shortcut$
MenuItem(ItemID, Text$)
If Not FindString(Text$, Chr(9)) : ProcedureReturn : EndIf
Shortcut$ = Mid(Text$, FindString(Text$, Chr(9)))
AddKeyboardShortcut(#WndMain, GetShortcutConstant(Shortcut$), ItemID)
EndProcedure
Thanks in advance!