Delphi/Lazarus: Enter-Key in Edit
Question by Guest | 2016-06-10 at 09:26
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 the keyword or the jump into the next input field or the automatic button press next to the field.
How can I realize that?
Related Topics
Delphi/Lazarus: Enter-Key in Edit-Field
Open Question | 5 Answers
Lazarus: Jump with Enter Key into next Row of StringGrid
Question | 1 Answer
Delphi/Lazarus: Prevent user from using CTRL+C in Memo or Edit Field
Tutorial | 0 Comments
Delphi: Show Path in Windows Explorer
Question | 1 Answer
Delphi/Lazarus: Catch CTRL+C in Memo or Edit and Change Clipboard Content
Tutorial | 0 Comments
Delphi/Lazarus: Round Number to the next 10, 100 or 1000
Question | 1 Answer
Delphi/Lazarus: Determine Mouse Position
Question | 1 Answer
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. 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.
2016-06-10 at 21:12
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