Delphi/Lazarus: Enter-Key in Edit
Question by Guest | Last update on 2024-01-03 | Created on 2016-06-10
I would like to execute a specific action automatically, whenever the enter respectively return key is pressed from within a TEdit field.
For example, this can be the automatic start of the search after entering a keyword, the jump into the next input field or the automatic press of the button next to the field.
How can I realize that?
Related Topics
Delphi/Lazarus: Is the ALT, SHIFT or CTRL key pressed?
Tutorial | 0 Comments
Delphi/Lazarus: Only allow Numbers in TEdit
Tip | 0 Comments
Delphi: System-Wide HotKey
Tutorial | 1 Comment
Delphi/Lazarus: Delete selected Items from ListBox using DEL-Key
Tip | 3 Comments
XAMPP: How to set up SSL/HTTPS for local Projects
Tutorial | 4 Comments
jQuery: Assign Action to Keyboard Keys (Keyboard Event)
Tip | 0 Comments
Delphi/Lazarus: Select all with CTRL+A in ListView
Tip | 0 Comments
Important Note
Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.
Participate
Ask your own question or write your own article on askingbox.com. That’s how it’s done.
You can just react to the enter key in the OnKeyPress event of the Edit field.
The return key has the key code #13, so the if statement could look something like that:
In this example, we are just calling the procedure Button1Click, so that the therein contained code will be executed after pressing the enter key, and we jump to the next edit field. Of course, you can also execute or write any other code or function at this point.
It is important to set the key to #0 afterwards. With this, you prevent the Edit from further processing the input.
Last update on 2024-01-03 | Created on 2016-06-10
If a button should be clicked when pressing the enter key, you can also set the property "Default" of the button to "true". With this, the button will be clicked automatically when pressing Enter.
The same applies for the ESC key. In this case, you have to set the property "Cancel" to "true".
2016-06-11 at 20:12
This solution is better for smaller programs or dialog windows!
The above answer is more suitable for longer programs.
2023-06-12 at 21:38