Page 1 of 1
Trigger event for Enter on ButtonGadgets
Posted: Sun Jun 30, 2013 1:27 am
by PB
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?
Re: Trigger event for Enter on ButtonGadgets
Posted: Sun Jun 30, 2013 4:43 am
by BorisTheOld
PB wrote:But pressing Enter on it does nothing.
It does for Linux, but not for Windows.
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.
Re: Trigger event for Enter on ButtonGadgets
Posted: Sun Jun 30, 2013 4:51 am
by PB
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.
Re: Trigger event for Enter on ButtonGadgets
Posted: Sun Jun 30, 2013 11:53 am
by jassing
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.
It's standard windows object behaviour-- You can define a button to be "default" and that should trigger if the window received 'enter'.
Re: Trigger event for Enter on ButtonGadgets
Posted: Sun Jun 30, 2013 4:11 pm
by BorisTheOld
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'.
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.
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.
Re: Trigger event for Enter on ButtonGadgets
Posted: Mon Jul 01, 2013 9:17 am
by PB
> 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:
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
Re: Trigger event for Enter on ButtonGadgets
Posted: Mon Feb 21, 2022 9:03 pm
by doctorized
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
Posted: Mon Feb 21, 2022 11:07 pm
by mk-soft
On windows is Enter is not a valid key for buttons
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
Re: Trigger event for Enter on ButtonGadgets
Posted: Tue Feb 22, 2022 12:38 am
by BarryG
mk-soft wrote: Mon Feb 21, 2022 11:07 pmOn windows is Enter is not a valid key for buttons
What? It certainly is for Win32 executables. Or are you referring to PureBasic exes?