I made a quick keyboard shortcut code.
I tried making a
Code: Select all
If Not shortcutnr: shortcutnr=GetActiveGadget(): EndIf
but it didnt work, probably because the gadget is made after the caption is set and not the other way around.
There are plenty of improvements that can be made here...
Code: Select all
Procedure.s shortcut(string.s,shortcutnr=0)
If Not GetActiveWindow() Or Not string.s
ProcedureReturn
EndIf
If Mid(string,FindString(string,"&")+1,1)="0"
If Not shortcutnr: shortcutnr=GetActiveGadget(): EndIf
AddKeyboardShortcut(GetActiveWindow(),#PB_Shortcut_Alt | (48),shortcutnr)
ElseIf Val(Mid(string,FindString(string,"&")+1,1))
If Not shortcutnr: shortcutnr=GetActiveGadget(): EndIf
AddKeyboardShortcut(GetActiveWindow(),#PB_Shortcut_Alt | (48+Val(Mid(string,FindString(string,"&")+1,1))),shortcutnr)
ElseIf Mid(UCase(string),FindString(string,"&")+1,1)>"A" And Mid(UCase(string),FindString(string,"&")+1,1)<"Z"
If Not shortcutnr: shortcutnr=GetActiveGadget(): EndIf
AddKeyboardShortcut(GetActiveWindow(),#PB_Shortcut_Alt | (Asc(UCase(Mid(string,FindString(string,"&")+1,1)))),shortcutnr)
EndIf
ProcedureReturn string.s
EndProcedure
OpenWindow(#PB_Any,0,0,320,200,"Test")
OptionGadget(1,0,0,100,24,shortcut("This &is a test",1))
OptionGadget(2,0,30,100,24,shortcut("This i&s a test",2))
Repeat
eventid=WaitWindowEvent()
If eventid=#PB_Event_Menu
If IsGadget(EventMenu())
SetActiveGadget(EventMenu())
SetGadgetState(EventMenu(),1-GetGadgetState(EventMenu()))
EndIf
EndIf
Until eventid=#PB_Event_CloseWindow
What I do is basicly copying the gadget numbers to menu numbers. So in case you use a popupmenu or whatever it should have a different number series.