Link to home
Start Free TrialLog in
Avatar of Roger Alcindor
Roger Alcindor

asked on

FMX TEdit KeyUp handler detecting "enter" key

I wish to perform some action (simulation of clicking a button foe example) when the enter key (carriage return) is pressed and released in an FMX Edit control. The following code using the TEdit KeyUp event doesn't seem to work, what should I be doing ?
I am using the Embarcadero  C++ builder XE 10.1 Berlin compiler.


void __fastcall TForm1::Edit1KeyUp(TObject *Sender, WORD &Key, System::WideChar &KeyChar,
          TShiftState Shift)
{
    WideChar w = '\r';

	if(KeyChar==w)
		Button1Click(NULL);
}

Open in new window

Avatar of sarabande
sarabande
Flag of Luxembourg image

you may try the Edit1KeyDown as the WM_CHAR is not issued at all for VK_RETURN and the WM_KEYUP might not be handled if there was already a handler before.

VK_RETURN ('\r' or 0x0D) often was handled by accelerators. in a form enter key would be redirected to a button-click of the default pushbutton (normally the ok button). in the OnOk you could find out if the return key was pressed by checking whether the ok button has not the focus.

Sara
Avatar of Roger Alcindor
Roger Alcindor

ASKER

Thanks for your comment, I get the same for Edit1KeyDown. I have solved the problem initially by using the event handler's Key parameter as follows but this does not agree with the  documentation which suggests that the Key parameter is the specific code at the keyboard hardware level. In both KeyDown and KeyUp, the value of the KeyChar character is L"" when the return or Enter key is entered.
So I have changed the code as follows:

void __fastcall TForm1::Edit1KeyUp(TObject *Sender, WORD &Key, System::WideChar &KeyChar,
		  TShiftState Shift)
{
	if(KeyChar=='\0')
		Button1Click(NULL);
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of sarabande
sarabande
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for your comments. I will investigate further to determine how to implement the code that you suggest.

Roger