Page 1 of 1

SendTouchEvent

Posted: Thu Jul 18, 2024 6:22 pm
by sodlf159
procedure TForm1.SendTouchEvent(eventType: string; x, y: Integer);
var
TempParams: ICefDictionaryValue;
TouchPoints: ICefListValue;
TouchPoint: ICefDictionaryValue;
begin
TempParams := TCefDictionaryValueRef.New;
TouchPoints := TCefListValueRef.New;
TouchPoint := TCefDictionaryValueRef.New;

TouchPoint.SetInt('x', x);
TouchPoint.SetInt('y', y);
TouchPoint.SetInt('radiusX', 10); // Sets the radius of the touch point.
TouchPoint.SetInt('radiusY', 10);
TouchPoint.SetDouble('force', 1); // Set the touch pressure.
TouchPoint.SetInt('rotationAngle', 0);
TouchPoints.SetDictionary(0, TouchPoint);

TempParams.SetList('touchPoints', TouchPoints);
TempParams.SetString('type', eventType);

Chromium1.ExecuteDevToolsMethod(0, 'Input.dispatchTouchEvent', TempParams);
end;


procedure TForm1.Chromium1RenderCompMsg(Sender: TObject;
var aMessage: TMessage; var aHandled: Boolean);
var X, Y: Integer;
begin
if FClosing then
Exit;

case aMessage.Msg of
WM_LBUTTONDOWN:
begin
X := LOWORD(aMessage.LParam);
Y := HIWORD(aMessage.LParam);
DispatchTouchEvent(Chromium1, 'touchStart', X, Y);
FTouchActive := True;
aHandled := True;
end;
WM_MOUSEMOVE:
begin
if FTouchActive then
begin
X := LOWORD(aMessage.LParam);
Y := HIWORD(aMessage.LParam);
DispatchTouchEvent(Chromium1, 'touchMove', X, Y);
aHandled := True;
end;
end;
WM_LBUTTONUP:
begin
if FTouchActive then
begin
X := LOWORD(aMessage.LParam);
Y := HIWORD(aMessage.LParam);
DispatchTouchEvent(Chromium1, 'touchEnd', X, Y);
FTouchActive := False;
aHandled := True;
end;
end;
end;
end;

FTouchActive : Boolean;

Mobile agent required

I really need it.
Please add it to the mobile demo section.

In the case of buttons, you can move them by sliding.

For buttons, you can slide them to move them. :D :D


///////////////

document.addEventListener('touchstart', function(event) {
console.log('touchstart', event);
});

document.addEventListener('touchmove', function(event) {
console.log('touchmove', event);
});

document.addEventListener('touchend', function(event) {
console.log('touchend', event);
});

///////////////

Re: SendTouchEvent

Posted: Fri Jul 19, 2024 4:22 pm
by salvadordf
I just uploaded a new CEF4Delphi version with some functions to simulate mouse, touch and keyboard events.
  • Added TChromiumCore.SimulateMouseEvent
  • Added TChromiumCore.SimulateTouchEvent
  • Added TChromiumCore.SimulateEditingCommand
  • Fixed TChromiumCore.SimulateKeyEvent
  • Added EditingCommandToString
The rest of the code is specific to your application.