Vektor88
Vektor88

Reputation: 4930

Injection of touch events using screen driver

Using android-event-injector library, I wrote an application to inject a touch event when some event is triggered. The problem is that i need to inject touch at absolute coordinates of a given View, so I do the following to get the location on screen:

View v = /* find view*/;
int [] coords = new int[2];
v.getLocationOnScreen(coords);

This gives me the absolute coordinates on screen. The problem is that touch injection doesn't work.

I can inject correctly touches in screen driver, but for some reason the coordinates are misunderstood and touches are injected elsewhere. Here are some examples (my screen is 1024x600 landscape oriented):

Upvotes: 2

Views: 2089

Answers (1)

TheCodeArtist
TheCodeArtist

Reputation: 22497

Based on the sample values it appears that the

  1. Touchscreen is (600, 1024),
  2. Mapped to a (1024,600) display.

To generate a touch event at (X,Y)display co-ordinates, the (x,y)touch co-ordinates that need to be injected can be calculated as follows

x(touch) = (600/1024) * X(disp)
y(touch) = (1024/600) * Y(disp)

Upvotes: 4

Related Questions