Mega Code Archive

 
Categories / Delphi / System
 

ENTER key instead of TAB key

Title: ENTER key instead of TAB key Question: If you have users that come from the DOS world, then they probably would rather use the ENTER key to move from component to component than use the TAB key. Answer: // Up in your Public declarations in your Main form procedure MsgHandler(var Msg: TMsg; var Handled: Boolean); // and then inside your main form's create event, // add this line so that all messages // get sent through your own message handler Application.OnMessage := Self.MsgHandler; // then create create this procedure in your main form // so that if the windows message is // a keydown and it is a RETURN key and the focused // control is a DBEdit control (add whatever // other controls here so that you can control how // the ENTER key is handled depending on // the type of focused control). You may also want // to add a global variable that enables you // to turn on/off the "ENTER = TAB" functionality. // Some people like the true Windows interface, // while others (usually people coming from the DOS // world, like the ENTER key :). procedure TfrmMain.MsgHandler(var Msg: TMsg; var Handled: Boolean); var ActiveControl: TWinControl; begin if (Msg.message = WM_KEYDOWN) AND (Msg.wParam = VK_RETURN) then begin ActiveControl := Screen.ActiveControl; // if the active control inherits from TDBEdit, // then change the key to a TAB. Obviously, if you want // the ENTER key to be intercepted while in another // component, just add that component to this IF statement. if ActiveControl.InheritsFrom(TDBEdit) then Msg.wParam := VK_TAB; end; end; Hope you find this useful! :) Scott