procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; var KeyChar: Char; Shift: TShiftState); begin if Key = vkReturn then begin Memo1.Lines.Add('按了回车') end; end;
KeyDown or KeyPress events: any component (forms, edits, etc...)
procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin if (Key = 13) then ShowMessage('ENTER KeyDown'); end;
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char); begin if (Key = Chr(13) { #13 } ) then ShowMessage('ENTER KeyPress'); end;
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
MEMO dont capture "RETURN key" by default! -- "non-printable characters are captured" to internal process and cannot be handled easyly, it's necessary change the "FMX" internal use of JAVA class in "C:\RADStudio\RX112\source\rtl\androiddex\java\fmx\src\com\embarcadero\firemonkey\text\FMXEditText.java" or others
More easy, try this: FORM "OnKeyDown" occurs before that your childs
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; var KeyChar: Char; Shift: TShiftState); begin Label1.Text := TimeToStr(now) + ' FORM: key = ' + Key.ToString; end;
procedure TForm1.MyOnKeyDown(Sender: TObject; var Key: Word; var KeyChar: Char; Shift: TShiftState); begin Label2.Text := TimeToStr(now) + ' CONTROL: key = ' + Key.ToString; end;
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
Intercept KeyEvent on Android with Delphi Some days ago, I had the needed to intercept the KeyDown Event on Android. In particullary the App have to respond to FormKeyDown Event. After some work I found out that there is an opened issue about this topic (https://quality.embarcadero.com/browse/RSP-10111 - vote it if you need its resolution). So I set to work to find a solution/workaround to solve my need. I studied Android SDK and Delphi internal mechanism and I found out a way to resolve it: By adding a JFMXTextListener to JFMXTextEditorProxy JFMXTextEditorProxy is an object provided by the JFMXNativeActivity (The activity for all your Android application in Delphi) and provides the method addTextListener to register a JFMXTextListener. JFMXTextListener is an interface that supply 3 methods to manage text event:
MyOnKeyDown is same that "OnKeyDown event on forms/components"
TForm1 ... public / private -> procedure MyOnKeyDown(Sender: TObject; var Key: Word; var KeyChar: Char; Shift: TShiftState); ...
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3