The keybord accelerator for ButtonGadget
Posted: Thu Sep 15, 2005 5:42 pm
Is it possible to add the keybord accelerator for ButtonGadget: similiar to AddKeyboardShortcut for menu ?
Jan
Jan
http://www.purebasic.com
https://www.purebasic.fr/english/
Code: Select all
Enumeration 1
#Window_Form1
#Gadget_Form1_Button2
#Gadget_Form1_Text2
#Gadget_Form1_Text3
#Button2_Shortcut = 13101 ; I obtained this number by adding the keyboard shortcut
EndEnumeration ; and debugging the window event that fires when you press ctrl-F.
; It WILL be a different number in your program depending on what gadgets
; you have that fire events
If OpenWindow(#Window_Form1,277,165,400,300,#PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_Invisible,"Shortcut Example by Network Maestro")
If CreateGadgetList(WindowID(#Window_Form1))
ButtonGadget(#Gadget_Form1_Button2,130,240,115,20,"Do Stuff Now")
TextGadget(#Gadget_Form1_Text2,120,70,190,15,"CTRL_F Presses the button")
TextGadget(#Gadget_Form1_Text3,130,145,190,15,"The rain in Spain")
HideWindow(#Window_Form1,0)
EndIf
EndIf
AddKeyboardShortcut(#Window_Form1, #PB_Shortcut_Control | #PB_Shortcut_F, #Button2_Shortcut)
quitForm1=0
Repeat
EventID =WaitWindowEvent()
GadgetID =EventGadgetID()
;Process shortcuts first
If EventID = #Button2_Shortcut ;if the control-F shortcut was pressed,
EventID = #PB_Event_Gadget ;just change the event details to same as button2 press
GadgetID = #Gadget_Form1_Button2 ;and then process the events normally
EndIf
Select EventID
Case #PB_Event_CloseWindow
quitForm1=1
Case #PB_Event_Gadget
Select GadgetID
Case #Gadget_Form1_Button2
If GetGadgetText(#Gadget_Form1_text3) = "The rain in Spain"
SetGadgetText(#Gadget_Form1_text3, "Falls mainly on the plain")
Else
SetGadgetText(#Gadget_Form1_text3, "The rain in Spain")
EndIf
EndSelect
EndSelect
Until quitForm1
CloseWindow(#Window_Form1)
End