That Marc
That Marc

Reputation: 1224

Delphi - Simulate (multi)touch input

Is there an actual way of simulating the touch input inside of delphi app, and if so, is it possible to simulate multi touch as well?

The problem example: certain app accepts only touch input for some actions.

The desired solution example: Use keyboard keys to simulate the touch inputs. It could be vital/very desired, to be able to use Key "A" to simulate touch on coordinates (x, y), Key "B" on (x+n, y+m), and to be able to press either one by one or both keys simultaneously. (The physical limit of 3 keys here should be ignored).

Upvotes: 0

Views: 1296

Answers (1)

FMXExpress
FMXExpress

Reputation: 1276

I don't know about multi touch but you can simulate a mouse click (single touch). Will not work on things like TWebBrowser, TMapView, and maybe TListView. Theoretically you could modify the source code of where Firemonkey gets it's multi touch data from the hardware and send in your own data at that point but that is beyond the scope of this answer.

function TForm1.FindControlAtPoint(aParent: TControl; aPos: TPointF): TControl;
var
  I: Integer;
  Control, ChildControl: TControl;
  S: String;
begin
  Result := nil;

  // Check all the child controls and find the one at the coordinates
  for I := aParent.Controls.Count – 1 downto 0 do
  begin
    Control := aParent.Controls[I];
    S := Control.ClassName;
    if Control.PointInObject(aPos.X, aPos.Y) then
    begin
      ChildControl := FindControlAtPoint(Control, aPos);
      if Assigned(ChildControl) and ChildControl.HitTest then
        Exit(ChildControl)
      else if Control.HitTest then
        Exit(Control);
    end;
  end;
end;

There is a demo project available here.

Upvotes: 2

Related Questions