Page 1 of 1

Simulate a backspace key

Posted: Thu May 29, 2025 7:41 pm
by whisper1980
Still evaluating TRichView, but is there a way on mobile to simulate a backspace key (from an on-screen button)? Simulating the Enter key was easy, but I can't figure out how to simulate a virtual keyboard's backspace key.

Some background...
On a phone, having the keyboard popup whenever the user taps into the editor is not desired mostly due to limited real estate, so I have a kbd key button on the toolbar so they can open it whenever they need it. However, they like having two buttons on the toolbar: Enter and Backspace, that they can use without having to bring up the keyboard just to do either of those two (the kbd popup frequently blocks what they want to modify). I tried using an HTML editor for the mobile app, but it is too incompatible with our Windows app to convert between HTML and RTF, but that editor has a delete previous character function. Anyway, the data collection app on mobile has an unlimited number of what I call RapidRemarks that inspectors can use to populate their findings. So the Enter key button is extremely helpful for being able to add spacing to accommodate the RapidRemark. The backspace is also very helpful if they want to remove some pre-existing text or to remove empty lines without having to select>delete.

Re: Simulate a backspace key

Posted: Fri May 30, 2025 1:13 pm
by Sergey Tkachenko
In VCL version, you can use SendMessage:

SendMessage(RichViewEdit1.TopLevelEditor.Handle, WM_KEYDOWN, VK_BACK, 0)

Re: Simulate a backspace key

Posted: Fri May 30, 2025 4:01 pm
by whisper1980
Unfortunately, I'm using FMX on Android and iOS.

Re: Simulate a backspace key

Posted: Sun Jun 01, 2025 2:24 pm
by Sergey Tkachenko
TCustomRichViewEdit has a method for processing Backspace:

Code: Select all

procedure OnBackSpacePress(Ctrl: Boolean);
But this method is protected.
You can try to call it in this way:

Code: Select all

type
  TCustomRichViewEditHack = class (TCustomRichViewEdit)
  end;
...
  TCustomRichViewEditHack(RichViewEdit1.TopLevelEditor).OnBackSpacePress(False);
But it needs to be tested how this hack works on mobile platforms.
I hope you use Delphi 12.x.
In earlier versions of Delphi, keyboard input in Android was handled by changing text instead of processing keys.