Spikey: Your comment explains all. I will just add that the main trick in BarryG's code is that he uses the corresponding (the same) numbering for buttons and keyboard shortcuts and - in my opinion - is the meaning of using "Event" from the PureBasic command.
Years ago, I was a Basic user called CARealizer. (I even wrote an app in it.) With CARealizer, you could automatically add keyboard shortcuts to buttons, and you could underline letters with ampersands: if, for example, my button was called "Button activated with Shift+A" - then if I wrote "Button &activated with Shift+A" the letter "a" in the word "activated" would be underlined on the button. Is it possible to get something like this in PureBasic. If NOT, I will use GadgetToolTip to teach the users to quickly switch to keyboard shortcuts. It is known that tip text is displayed when the mouse cursor is over the gadget. I also decided that the keyboard shortcuts will not be Ctrl but Shift combinations, because Ctrl is often used (for example: Ctrl+n, Ctrl+o, Ctrl+s, Ctrl+w, etc.), and I can't break users habits. I finally adopted this code for use in my application:
Code: Select all
If OpenWindow(0, 0, 0, 222, 200, "ButtonGadgets activated with Shift", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ButtonGadget(0, 10, 30, 200, 30, "Button activated with Shift+A")
GadgetToolTip(0, "You can also activate this button with the Shift + A key combination")
ButtonGadget(1, 10, 95, 200, 30, "Button activated with Shift+B")
GadgetToolTip(1, "You can also activate this button with the Shift + B key combination")
ButtonGadget(2, 10, 160, 200, 30, "Button activated with Shift+C")
GadgetToolTip(2, "You can also activate this button with the Shift + C key combination")
AddKeyboardShortcut(0, #PB_Shortcut_Shift | #PB_Shortcut_A, 0)
AddKeyboardShortcut(0, #PB_Shortcut_Shift | #PB_Shortcut_B, 1)
AddKeyboardShortcut(0, #PB_Shortcut_Shift | #PB_Shortcut_C, 2)
; AddKeyboardShortcut(#Window, Shortcut, Event)
; Add Or replace a keyboard shortcut To the specified window. A shortcut generates a menu
; Event (like a menu item) As most of them are used in conjunction With menus.
Repeat
event = WaitWindowEvent()
Select event
Case #PB_Event_CloseWindow
Break
Case #PB_Event_Gadget, #PB_Event_Menu
If event = #PB_Event_Gadget
which = EventGadget()
Else
which = EventMenu()
EndIf
Select which
Case 0
MessageRequester("Keyboard shotcuts", "It is click on the button or activated with Shift+A")
Case 1
MessageRequester("Keyboard shotcuts", "It is click on the button or activated with Shift+B")
Case 2
MessageRequester("Keyboard shotcuts", "It is click on the button or activated with Shift+C")
EndSelect
EndSelect
ForEver
EndIf