In my project of remote assistence for smartphones android, i'm trying simulate touch on screen (using AccessibilityService
) based in coordinates of mouse inside a Image
component (Delphi), that is where i receives the screen of remote device.
Image
component is inside aScrollBox
component
Image
component is: Align: alNone, AutoSize: TrueScrollBox
is: Align: alClient, AutoScroll: True, AutoSize: False
Code of redimension of Image
component:
procedure TForm2.Checkbox1Click(Sender: TObject);
begin
if Checkbox1.Checked then
begin
Image1.AutoSize := false;
Image1.Stretch := true;
Image1.Align := alClient;
end
else
begin
Image1.AutoSize := true;
Image1.Stretch := false;
Image1.Align := alNone;
end;
end;
This is how i send coordinates:
procedure TForm2.Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
X := (X * Image1.Width) div Image1.Width;
Y := (Y * Image1.Height) div Image1.Height;
SS1.Socket.Connections[Index].SendText('touch' + IntToStr(X) +
'<|>' + IntToStr(Y) + #13#10);
end;
Then i tried this on Java code (android):
String xline;
if (xline.contains("touch")) {
String coordinates = xline.replace("touch", "");
String[] tokens = coordinates.split(Pattern.quote("<|>"));
float x = parseFloat(tokens[0]);
float y = parseFloat(tokens[1]);
int screenWidth = getResources().getDisplayMetrics().widthPixels;
int screenHeight = getResources().getDisplayMetrics().heightPixels;
x = (x * screenWidth) / screenWidth;
y = (y * screenHeight) / screenHeight;
// touch on screen with x and y
}
but the touch is happens in a place very distant.
How fix this?