Again....Enter key on a ButtonGadget

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
C87
Enthusiast
Enthusiast
Posts: 176
Joined: Mon Jul 17, 2017 7:22 am
Location: Cotswolds England

Again....Enter key on a ButtonGadget

Post by C87 »

I've been writing software since the dark days of MS-DOS and CP/M and I've only just discoverd that the <SpaceBar> activates a button! :lol:
Mind you buttons didn't exist until the late 1990s..........for me anyway! I thought I'd share that discovery because I have recently been
trying to get the <Enter> key to activate a ButtonGadget(). And because nobody suggested ; why not use the <SpaceBar> on a button instead?

On a Windows screen I think it is normal to press <Tab> or <Shift>+<Tab> to move around fields and gadgets. Also, I think it is normal
to use the <Enter> key to move from the current field down to the next in the set Tab order. Maybe I'm wrong or alone with this opinion?

In the course of looking for a solution for <Enter> on a button, I posted the following request for help : How to Enable key press options to a ButtonGadget()
viewtopic.php?f=13&t=76301&hilit=How+to ... ttonGadget

Rashad's solution does operate the shortcut keys from wherever the cursor is, which is great. Rashad's code will also trigger the buttons using the <Enter> key.

I also found some earlier posts and one example I looked at was : Window event carriage return
viewtopic.php?f=22&t=74603&hilit=Window ... age+return

This example appears to work, but it actually doesn't. The <Enter> is only accepted from the password field. If I tab to the ButtonGadget(3), [Login],
then press the <Enter>, the DoLogin Proc is not called. If it is LeftClicked with the mouse it will of course operate the DOLogin Proc. But even with the
button still in focus after the mouseclick it will not trigger DoLogin with <Enter>.

It was testing these two examples I discovered that the <SpaceBar> triggers a button. I then went back through my older software and found that it
applied with all of them! I always knew the <SpaceBar> selected CheckBoxes etc but not a button. For most applications using the <SpaceBar> is as
convenient as <Enter> for a button but the <Enter> key cannot accidentally clear the contents of a field, as the <SpaceBar> can.

I am suggesting that that the <Enter> keyshould activate the ButtonGadget(), as the current <SpaceBar> and LeftMouseClick do. Also, it would be
helpful at times for the <Enter> key to move the cursor to the next field on a screen. As the Tab key does, but without needing to add code to force it.

Maybe these are candidates for Feature Requests and Wishlists?
If it's falling over......just remember the computer is never wrong!