http://www.purebasic.fr/english/viewtop ... 6&p=456894
This procedure sets up keyboard shortcuts for the char that immediately
follows the ampersand char. Makes it simple to set up the shortcuts. Run
it as-is at first, then comment the first two gadget lines and uncomment
the second two gadget lines and run again, to see how it easily adapts to
whatever shortcut text is used.

As I said, this is just a starting point to show auto-shortcuts can be done
without lots of extra coding. But it doesn't do any error-checking with any
other keyboard shortcuts that you may have, etc. Work on it.

Code: Select all
Procedure AutoKeyboardShortcuts()
For gad=1 To 2
text$=GetGadgetText(gad)
pos=FindString(text$,"&")
If pos<>0 And CountString(text$,"&")=1
c=Asc(UCase(Mid(text$,pos+1,1)))
AddKeyboardShortcut(0,c,c)
EndIf
Next
EndProcedure
OpenWindow(0,200,200,150,120,"test",#PB_Window_SystemMenu)
ButtonGadget(1,20,20,100,25,"Enter &username")
ButtonGadget(2,20,60,100,25,"Enter &password")
;ButtonGadget(1,20,20,100,25,"Enter &name")
;ButtonGadget(2,20,60,100,25,"Enter &code")
AutoKeyboardShortcuts()
Repeat
ev=WaitWindowEvent()
If ev=#PB_Event_Menu
Debug "You pressed: "+Chr(EventMenu())
EndIf
Until ev=#PB_Event_CloseWindow