Page 1 of 2
Allow Enter key to action gadgets
Posted: Sat Dec 07, 2024 3:52 am
by BarryG
The vision-impaired user of my app is upset because the Enter key can't be used on ButtonGadgets/ButtonImageGadgets. I've made a workaround, but my request is that pressing Enter on one of those gadgets will act like Space was pressed on it, to cater for blind or accessibility reasons.
Code: Select all
If OpenWindow(0, 0, 0, 222, 70, "ButtonGadgets", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ButtonGadget(0, 10, 10, 200, 20, "Standard Button")
ButtonImageGadget(1, 10, 40, 200, 20, 9)
SetActiveGadget(0)
Repeat
ev = WaitWindowEvent()
If ev = #PB_Event_Gadget
Debug "Button pressed" ; <- This is the goal when I press Enter on a ButtonGadget/ButtonImageGadget.
EndIf
Until ev = #PB_Event_CloseWindow
EndIf
Re: Allow Enter key to action gadgets
Posted: Sat Dec 07, 2024 6:21 am
by Little John
Using AddKeyboardShortcut() in your app should work fine.
Re: Allow Enter key to action gadgets
Posted: Sat Dec 07, 2024 10:44 am
by BarryG
Already got a workaround, as mentioned. This is a request so workarounds (or hacks) aren't needed.
Re: Allow Enter key to action gadgets
Posted: Sat Dec 07, 2024 11:11 am
by Little John
What you are requesting is not standard behaviour of a user interface. Such a user interface would be confusing for most users. It doesn't make sense to build something like that into PB, just because 1 user of 1 app likes it.
(And by the way, what exactly is the problem with pressing the space key?)
Re: Allow Enter key to action gadgets
Posted: Sat Dec 07, 2024 11:33 am
by BarryG
Literally every app I just tried accepts the Enter key on a button... except PureBasic. But we can ignore the checkbox and optiongadgets, then.
As for why the Space bar isn't good enough: I don't know. It's a request from a blind user so maybe they need it for accessibility.
Re: Allow Enter key to action gadgets
Posted: Sat Dec 07, 2024 11:36 am
by Gérard
Code: Select all
Enumeration Window
#WinApp
EndEnumeration
If OpenWindow(#WinApp, 0, 0, 222, 70, "ButtonGadgets", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ButtonGadget(0, 10, 10, 200, 20, "Standard Button")
ButtonImageGadget(1, 10, 40, 200, 20, 9)
SetActiveGadget(0)
Repeat
ev = WaitWindowEvent()
If GetActiveWindow() = #WinApp
ActiveGadget = GetActiveGadget()
VK_RETURN = GetAsyncKeyState_(#VK_RETURN)
If VK_RETURN > 1
Select ActiveGadget
Case 0, 1
Debug "Button "+ActiveGadget+" pressed by Enter"
EndSelect
EndIf
EndIf
If ev = #PB_Event_Gadget
Debug "Button pressed" ; <- This is the goal when I press Enter on a ButtonGadget/ButtonImageGadget.
EndIf
Until ev = #PB_Event_CloseWindow
EndIf
Re: Allow Enter key to action gadgets
Posted: Sat Dec 07, 2024 11:40 am
by Little John
BarryG wrote: Sat Dec 07, 2024 11:33 am
Literally every app I just tried accepts the Enter key on a button... except PureBasic. But we can ignore the checkbox and optiongadgets, then.
On a
button ... yes, I agree.
BarryG wrote: Sat Dec 07, 2024 11:33 am
As for why the Space bar isn't good enough: I don't know. It's a request from a blind user so maybe they need it for accessibility.
Normally the space bar is even bigger than the Enter key.
Re: Allow Enter key to action gadgets
Posted: Sat Dec 07, 2024 11:49 am
by Fred
I think what you want is a default button for a dialog where enter validate it (usually on a button). It's natively supported on OSX (the button is blue) dunno about win32 and GTK/qt
Re: Allow Enter key to action gadgets
Posted: Sat Dec 07, 2024 11:59 am
by BarryG
No, not a default button. It works on any button with the focus rectangle on it. Try it with some Win32 exes and you'll see. Like a file browse button ("[...]") etc.
Re: Allow Enter key to action gadgets
Posted: Sat Dec 07, 2024 12:24 pm
by Little John
Standard behaviour on Windows (according to Charles Petzold):
When the focus is on any button, pressing [Enter] has the same effect as pressing the space bar, that is the effect takes place that is associated with that button.
When the focus is not on a button but on a different gadget, pressing [Enter] triggers the action of the default button.
Re: Allow Enter key to action gadgets
Posted: Sat Dec 07, 2024 12:43 pm
by BarryG
Exactly what I'm requesting.

Re: Allow Enter key to action gadgets
Posted: Sat Dec 07, 2024 12:46 pm
by Little John
Yes, after you have removed the part with checkbox and optiongadgets.

Re: Allow Enter key to action gadgets
Posted: Sat Dec 07, 2024 1:07 pm
by BarryG
Yep, because I responded to you about that:
BarryG wrote: Sat Dec 07, 2024 11:33 amwe can ignore the checkbox and optiongadgets, then.

Re: Allow Enter key to action gadgets
Posted: Sat Dec 07, 2024 5:58 pm
by emperor-limitless
Blind here, and I can confirm pressing enter to activate buttons is a standard for us, unlike sighted people, we use enter for everything that has an activation, we're not talking blind as has low sight, we're talking as in, totally blind, 0 sight or close to it, we use a technology called screen readers which uses keyboard for 99% of interaction, almost 0 mouse.
button size doesn't, exactly matter, thing is, while yes, people could go use space, it's like to you sighted people when things are colored to hurt your eyes or you're doing something non-standard in a normal ui and it gets annoying, almost everyone is used to enter to click on something, if it didn't work that would be unexpected and strange, some people don't even know that space could be used for clicking, in fact this is exactly why I don't use pb for coding gui programs, because I know I'll get endless complaints and people will likely ignore my program because using it is inconvenient or some people will think it's broken. Sometimes one inconvenience can be enough for something to not be used, I know it sounds ridiculous and something very small but imagine if you're used to moving the mouse in a touchpad or something with one finger, then suddenly some random program requires you to use 2 fingers, you will know that but you'll keep accidentally using one finger, get frustrated, then find another ulternative.
Re: Allow Enter key to action gadgets
Posted: Sun Dec 08, 2024 1:40 am
by BarryG
emperor-limitless wrote: Sat Dec 07, 2024 5:58 pmBlind here, and I can confirm pressing enter to activate buttons is a standard for us, unlike sighted people, we use enter for everything that has an activation
Thanks for confirming, emperor-limitless. Your response matches what my blind user has requested, so I'm glad my workaround (and this request) wasn't in vain. I sent him a private beta version yesterday and am still waiting on his response. Hopefully he's happy with it.
