Mega Code Archive

 
Categories / Delphi / System
 

Convert ENTER to TAB

Title: Convert ENTER to TAB Question: How can I use the ENTER key to move from one focusable control to another? Answer: In heads-down data entry the TAB key is a tripwire. Data entry personnel need a quick way to enter numbers and text without moving to the TAB key to move from one control to another. There are many solutions to this problem but the fasted [and slickest] way is to grab the keystroke before the form sees it: In the form's PRIVATE section enter: Procedure CMDialogKey(Var Msg:TWMKey); message CM_DIALOGKEY; In the form's IMPLEMENTATION section enter: Procedure TForm1.CMDialogKey(Var Msg: TWMKey); Begin If NOT (ActiveControl Is TButton) Then If Msg.Charcode = 13 Then Msg.Charcode := 9; inherited; End; Trapping for TButton (you can use other substitutions, as well) lets the button's ONCLICK event trigger when the user hits ENTER on a button. You do NOT have to activate the Form's KEYPREVIEW property, thereby speeding up the processing power of your application.