使用编程设定在Android触摸输入 [英] Use programming to set touch input on android

查看:141
本文介绍了使用编程设定在Android触摸输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用编程以模拟在画面上的位置(x,y)的一个接触。

I want to use programming to mimic a "touch" on a position (x, y) on the screen.

我看到这个的链接,但它只是教你如何注入的字符。

I saw this link, but it only teaches you how to inject characters.

我想触摸的位置注入(X,Y)

I want to inject a touch at position (x, y)

我如何做到这一点使用的Andr​​oid SDK(这是用java)?

How do I do this using Android SDK (which is java)?

推荐答案

可以假触摸事件是这样的:

You can "fake" a touch event like this:

MotionEvent event = MotionEvent.obtain(downTime, eventTime, action, x, y, metaState);
view.onTouchEvent(event);

API文档

创建一个新的MotionEvent,填补了   基本运动值的子集。   那些在这里没有规定是:设备   ID(始终为0),pressure和大小   (始终为1),x和y precision(总是   1),和edgeFlags(始终为0)。

Create a new MotionEvent, filling in a subset of the basic motion values. Those not specified here are: device id (always 0), pressure and size (always 1), x and y precision (always 1), and edgeFlags (always 0).

参数

  • 停机的时间(毫秒)时, 用户最初$ pssed下来,打开P $ 位置事件流。本 必须从获得 SystemClock.uptimeMillis()。
  • eventTime 的时间(毫秒)时, 生成此特定事件。 这必须从以下地址获得 SystemClock.uptimeMillis()
  • 动作的动作的类型是 完成 - 一个无论是 ACTION_DOWN ACTION_MOVE ACTION_UP ACTION_CANCEL
  • X 的X此事件的坐标。
  • 的y本次活动的协调。
  • 亚状态任何元的状态/ 修改键是为有效 当生成事件。
  • downTime The time (in ms) when the user originally pressed down to start a stream of position events. This must be obtained from SystemClock.uptimeMillis().
  • eventTime The the time (in ms) when this specific event was generated. This must be obtained from SystemClock.uptimeMillis().
  • action The kind of action being performed -- one of either ACTION_DOWN, ACTION_MOVE, ACTION_UP, or ACTION_CANCEL.
  • x The X coordinate of this event.
  • y The Y coordinate of this event.
  • metaState The state of any meta / modifier keys that were in effect when the event was generated.

<一个href="http://developer.android.com/reference/android/view/MotionEvent.html#obtain(long,%20long,%20int,%20float,%20float,%20int)"相对=nofollow>链接到API文档

这篇关于使用编程设定在Android触摸输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆