This might apply for other gadgets too, but I didn't test.
I noticed today that if I press Space on a ButtonGadget,
it triggers an event as though I clicked it with the mouse.
This is good, and wanted. But pressing Enter on it does
nothing. Can this be added to work like Space, please?
Trigger event for Enter on ButtonGadgets
Trigger event for Enter on ButtonGadgets
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
"PureBasic won't be object oriented, period" - Fred.
-
- Enthusiast
- Posts: 542
- Joined: Tue Apr 24, 2012 5:08 pm
- Location: Ontario, Canada
Re: Trigger event for Enter on ButtonGadgets
It does for Linux, but not for Windows.PB wrote:But pressing Enter on it does nothing.

We get around the problem by creating a custom event whenever a button has the focus and the Enter key is pressed.
We also create custom button events for Got-Focus and Lost-Focus. It's tricky, but it can be done without having to use operating system API code.
For ten years Caesar ruled with an iron hand, then with a wooden foot, and finally with a piece of string.
~ Spike Milligan
~ Spike Milligan
Re: Trigger event for Enter on ButtonGadgets
Yeah, at the moment I've had to make procedures to handle
the #WM_KEYDOWN and #PB_Event_Gadget events for both
Space and Enter.
Would rather it all be handled with #PB_Event_Gadget instead.
Not a priority request, but it makes everything all that easier.
the #WM_KEYDOWN and #PB_Event_Gadget events for both
Space and Enter.
Would rather it all be handled with #PB_Event_Gadget instead.
Not a priority request, but it makes everything all that easier.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
"PureBasic won't be object oriented, period" - Fred.
Re: Trigger event for Enter on ButtonGadgets
It's standard windows object behaviour-- You can define a button to be "default" and that should trigger if the window received 'enter'.PB wrote:Yeah, at the moment I've had to make procedures to handle
the #WM_KEYDOWN and #PB_Event_Gadget events for both
Space and Enter.
Would rather it all be handled with #PB_Event_Gadget instead.
Not a priority request, but it makes everything all that easier.
-
- Enthusiast
- Posts: 542
- Joined: Tue Apr 24, 2012 5:08 pm
- Location: Ontario, Canada
Re: Trigger event for Enter on ButtonGadgets
PB only allows this when the button is created. What's needed is the ability to have the button with focus respond to the Enter key.jassing wrote:It's standard windows object behaviour-- You can define a button to be "default" and that should trigger if the window received 'enter'.
Data entry operators find it more natural to use Enter to terminate a field, rather than use Tab or Spacebar, and certainly not the mouse.
For ten years Caesar ruled with an iron hand, then with a wooden foot, and finally with a piece of string.
~ Spike Milligan
~ Spike Milligan
Re: Trigger event for Enter on ButtonGadgets
> It's standard windows object behaviour-- You can define a button to
> be "default" and that should trigger if the window received 'enter'.
Doesn't work. Only Space triggers an event. Observe:
> be "default" and that should trigger if the window received 'enter'.
Doesn't work. Only Space triggers an event. Observe:
Code: Select all
If OpenWindow(0,300,250,400,200,"Button focus",#PB_Window_SystemMenu)
ButtonGadget(1,50,50,60,25,"Hit Enter",#PB_Button_Default)
ButtonGadget(2,150,50,60,25,"Button2")
ButtonGadget(3,250,50,60,25,"Button3")
SetActiveGadget(1)
Repeat
ev=WaitWindowEvent()
If ev=#PB_Event_Gadget
Debug EventGadget()
EndIf
Until ev=#PB_Event_CloseWindow
EndIf
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
"PureBasic won't be object oriented, period" - Fred.
- doctorized
- Addict
- Posts: 882
- Joined: Fri Mar 27, 2009 9:41 am
- Location: Athens, Greece
Re: Trigger event for Enter on ButtonGadgets
February 21th, 2022 and Enter is not triggering event. On the other hand, Space is triggering event just fine.
Re: Trigger event for Enter on ButtonGadgets
On windows is Enter is not a valid key for buttons
Solution:
Solution:
Code: Select all
Enumeration MenuItem
#MenuItem_Return
EndEnumeration
Procedure DoEventMenuReturn()
Protected gadget
gadget = GetActiveGadget()
If IsGadget(gadget) And GadgetType(gadget) = #PB_GadgetType_Button
PostEvent(#PB_Event_Gadget, GetActiveWindow(), gadget, #PB_EventType_LeftClick)
EndIf
EndProcedure
Procedure DoEventGadgetChangeFocus()
Protected gadget
gadget = EventGadget()
Select GadgetType(gadget)
Case #PB_GadgetType_Editor
Select EventType()
Case #PB_EventType_Focus
Debug "Remove Return"
RemoveKeyboardShortcut(0, #PB_Shortcut_Return)
Case #PB_EventType_LostFocus
Debug "Add Return"
AddKeyboardShortcut(0, #PB_Shortcut_Return, #MenuItem_Return)
EndSelect
EndSelect
EndProcedure
If OpenWindow(0,300,250,400,200,"Button focus",#PB_Window_SystemMenu)
CreateMenu(0, WindowID(0))
EditorGadget(0, 10, 10, 380, 140)
ButtonGadget(1, 50, 160, 60, 25,"Hit Enter",#PB_Button_Default)
ButtonGadget(2, 150, 160, 60, 25,"Button2")
ButtonGadget(3, 250, 160, 60, 25,"Button3")
SetActiveGadget(1)
BindEvent(#PB_Event_Gadget, @DoEventGadgetChangeFocus())
BindMenuEvent(0, #MenuItem_Return, @DoEventMenuReturn())
AddKeyboardShortcut(0, #PB_Shortcut_Return, #MenuItem_Return)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
Case #PB_Event_Gadget
Debug "Gadget " + EventGadget()
EndSelect
ForEver
EndIf
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Re: Trigger event for Enter on ButtonGadgets
What? It certainly is for Win32 executables. Or are you referring to PureBasic exes?