注射用屏驱动程序触摸事件 [英] 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.
我可以注入正常的触摸屏驱动程序,但由于某些原因的坐标被人误解和触摸在其他地方注射。 下面是一些例子(我的屏幕1024x600的横向定向):
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):
- 在坐标(0,0) - >注射(0,0)
- COORDS(0600) - >注入(0351)
- COORDS(1024,0) - >未注射(最有可能的x是超出范围)
- COORDS(1024,600) - >未注射(最有可能的x是超出范围)
- COORDS(640,480) - >未注射(最有可能的x是超出范围)
- COORDS(512300) - >注入(872175)
- COORDS(100,100) - >注射(170,58)
推荐答案
根据采样值看来,
- 触摸屏(600,1024),
- 映射到(1024,600)显示。
要产生以(X,Y)的显示坐标,第(x,y)的触摸坐标需要被注入可以计算如下的触摸事件
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)
这篇关于注射用屏驱动程序触摸事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!