[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Convenient way to parse Enter on a textbox?


On 9/22/25 8:58 AM, Admin wrote:
Greetings good people of Gambas!

This should be pretty common thing in visual programming to create a program that allows user to type something in a field and hit enter to make it work, send it, right? Like, in Chat clients or something.

So it should be pretty easy to trace Enter key while some textbox is in focus and react to it, is it not?

I have a program that has a textbox and a "send" button.

But.

It seems to me that even having a sub like <anything>_KeyPress() brings a lot of "entropy" in to my program. This routine seems to be an event handler which "destroys" any "wait"s in the program, does not allow an interface to redraw itself before moving on to some long task, and finally, it does not even work right away.

For example, in my Send button Sub I call another form to appear and then do "wait 0.1" for the form to actually appear, then I do other stuff. And it works. But if I call Button_Click sub from a KeyPress event of the textbox, it is ignored, debug window shows a warning that there is no use to call wait while keypress is active and the new form is not shown until all the routine of button_click is over.

The workaround I use now is to just button.setfocus on Enter keypress and then I expect user to press enter again. So it's basically two enters instead of one to send a string from a textbox. It works, but I feel stupid.

I strongly believe that it should be done much, much easier since it is a common task, and that I just don't understand Gambas enough.

Can you please teach me the right way?

Dmitry.

Just set the "Send" button's .Default property to True.
https://gambaswiki.org/wiki/comp/gb.qt4/button/default


--
Lee

--- Gambas User List Netiquette [https://gambaswiki.org/wiki/doc/netiquette] ----
--- Gambas User List Archive [https://lists.gambas-basic.org/archive/user] ----


Follow-Ups:
Re: Convenient way to parse Enter on a textbox?Admin <admin@xxxxxxxxxx>
References:
Convenient way to parse Enter on a textbox?Admin <admin@xxxxxxxxxx>