Disclosure Statement: This site contains affiliate links, which means that I may receive a commission if you make a purchase using these links. As an eBay Partner, I earn from qualifying purchases.

SendTouchEvent

Post Reply
sodlf159
Posts: 50
Joined: Thu Nov 09, 2023 1:55 pm

SendTouchEvent

Post 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);
});

///////////////
User avatar
salvadordf
Posts: 4304
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: SendTouchEvent

Post 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.
Post Reply