提问人:Fernando Gallego 提问时间:5/14/2014 最后编辑:Fernando Gallego 更新时间:5/14/2014 访问量:3747
在 android 上模拟鼠标输入
Simulate a mouse input on android
问:
想象一下,我有一个从蓝牙设备接收坐标的服务,现在我想在鼠标移动时显示鼠标光标。
我设法发送了带有 toolType = TOOL_TYPE_MOUSE 的 MotionEvents,但我没有在屏幕上显示原生 android 鼠标光标。
我发送的事件如下所示:
05-14 13:38:05.043: I/onTouchEvent(30301): MotionEvent { action=ACTION_DOWN, id[0]=0, x[0]=498.0, y[0]=996.0, toolType[0]=TOOL_TYPE_MOUSE, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=251957430, downTime=251957420, deviceId=1, source=0x2002 }
我是这样创建它们的:
public void moveMouse(int x, int y) {
// Obtain MotionEvent object
long downTime = SystemClock.uptimeMillis() - 10;
long eventTime = SystemClock.uptimeMillis();
int metaState = 0;
MotionEvent.PointerProperties p = new PointerProperties();
p.toolType = MotionEvent.TOOL_TYPE_MOUSE;
p.id = 0;
MotionEvent.PointerProperties[] properties = {p};
MotionEvent.PointerCoords c = new MotionEvent.PointerCoords();
c.x = x;
c.y = y;
c.orientation = 0f;
c.pressure = 1f;
c.size = 1f;
MotionEvent.PointerCoords[] coords = {c};
int buttonState = 0;
float precisionX = 1.0f;
float precisionY = 1.0f;
int deviceId = 1;
int edgeFlags = 0;
int flags = 0;
MotionEvent event;
event =
MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_DOWN, 1, properties,
coords, metaState, buttonState, precisionX, precisionY, deviceId,
edgeFlags, InputDevice.SOURCE_MOUSE, flags);
dispatchTouchEvent(event);
但我仍然看不到鼠标指针。我做错了什么?
答: 暂无答案
评论