Allow Enter key to action gadgets

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
BarryG
Addict
Addict
Posts: 4127
Joined: Thu Apr 18, 2019 8:17 am

Allow Enter key to action gadgets

Post 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
Last edited by BarryG on Sat Dec 07, 2024 11:35 am, edited 1 time in total.
Little John
Addict
Addict
Posts: 4777
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Allow Enter key to action gadgets

Post by Little John »

Using AddKeyboardShortcut() in your app should work fine.
BarryG
Addict
Addict
Posts: 4127
Joined: Thu Apr 18, 2019 8:17 am

Re: Allow Enter key to action gadgets

Post by BarryG »

Already got a workaround, as mentioned. This is a request so workarounds (or hacks) aren't needed.
Little John
Addict
Addict
Posts: 4777
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Allow Enter key to action gadgets

Post 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?)
BarryG
Addict
Addict
Posts: 4127
Joined: Thu Apr 18, 2019 8:17 am

Re: Allow Enter key to action gadgets

Post 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.
Gérard
User
User
Posts: 48
Joined: Sat Oct 17, 2015 6:00 pm
Location: France
Contact:

Re: Allow Enter key to action gadgets

Post 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
■ Win10 64-bit (Intel Celeron CPU N2920 @ 1.86GHz, 4,0GB RAM, Intel HD Graphics) & PB 6.00 LTS
■ Vivre et laisser vivre.
■ PureBasic pour le fun
■ cage sur le forum Français
■ Mes sites: http://pbcage.free.fr - http://yh.toolbox.free.fr
Little John
Addict
Addict
Posts: 4777
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Allow Enter key to action gadgets

Post 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.
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Allow Enter key to action gadgets

Post 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
BarryG
Addict
Addict
Posts: 4127
Joined: Thu Apr 18, 2019 8:17 am

Re: Allow Enter key to action gadgets

Post 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.
Little John
Addict
Addict
Posts: 4777
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Allow Enter key to action gadgets

Post 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.
BarryG
Addict
Addict
Posts: 4127
Joined: Thu Apr 18, 2019 8:17 am

Re: Allow Enter key to action gadgets

Post by BarryG »

Exactly what I'm requesting. :)
Little John
Addict
Addict
Posts: 4777
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Allow Enter key to action gadgets

Post by Little John »

Yes, after you have removed the part with checkbox and optiongadgets. :)
BarryG
Addict
Addict
Posts: 4127
Joined: Thu Apr 18, 2019 8:17 am

Re: Allow Enter key to action gadgets

Post 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.
;)
emperor-limitless
User
User
Posts: 11
Joined: Tue Nov 12, 2024 5:14 pm

Re: Allow Enter key to action gadgets

Post 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.
BarryG
Addict
Addict
Posts: 4127
Joined: Thu Apr 18, 2019 8:17 am

Re: Allow Enter key to action gadgets

Post 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. :)
Post Reply