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.
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);
}
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:
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);
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for your comments. I will investigate further to determine how to implement the code that you suggest.
Roger
Roger
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