How to handle non-English accented characters using a physical keyboard in an Android app written in Delphi?

  

Non-English languages often have diacritics (glyphs added to letters to alter the letters), such as the circumflex accent in French as inâ or ê. Those characters are generally obtained by first hitting a dead key on the keyboard, such as ^, followed by the letter on which we want to apply the diacritic. So, to obtain â, one has to press ^ followed by a to see â in the edit control.
When writing an Android app in Delphi using FireMonkey, the handling of those diacritics has always been problematic when a physical keyboard is attached to the Android device, whether it is via USB or Bluetooth.
For example, prior to Delphi 10.4.x, in a TEdit or a TMemo, pressing ^ followed by a would give ^a instead of the expected â. Note that applications not written in Delphi are not exhibiting this peculiar problem.
As of Delphi 10.4.x, the problem has been fixed for TEdit, but unfortunately TMemo is still plagued with the problem. Of course, if one is not using a physical keyboard, everything works perfectly. However, as I am trying to write an application that will support a physical keyboard, particularly in Samsung DeX mode, this poses a serious problem.
I am therefore asking for help in perhaps overriding the key handling of the TMemo, perhaps using the OnKeyDown event, to fix this problem that prevents my app from being used by non-English users.
Knowing that when pressing ^, in the OnKeyDown event we get Key = $0 and KeyChar = 710, I managed to intercept the diacritic and insert the accented letter, but I have not been able to remove the diacritic so pressing ^ followed by a gives ^â in the TMemo. I can’t figure out how to remove the ^ in front of the â.

private
{ Private declarations }
IsDeadKey: Boolean;
DeadKey: Char;


procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word; var KeyChar: Char; Shift: TShiftState);
begin
if IsDeadKey then
begin
if (Ord(DeadKey) = 710) then
begin
case KeyChar of
‘a’: KeyChar := ‘â’;
‘e’: KeyChar := ‘ê’;
end;
IsDeadKey := False;
end
else
begin
KeyChar := DeadKey;
IsDeadKey := False;
end;
end
else
if (Key = $0) and (Ord(KeyChar) = 710) then
begin
IsDeadKey := True;
DeadKey := KeyChar;
end;
end;

Comments are closed.