在 Android 上模拟触摸屏事件
后台进程或软键盘是否可以创建触摸事件并将其发送到屏幕,就像屏幕被实际触摸一样?
即模拟触摸屏事件。
Is it possible for a background process or softkeyboard to create touch events and send them to screen as if the screen was actually touched?
i.e. simulating touch screen events.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
SDK 附带了一个名为 Monkey 的工具,它会生成伪-用户事件的随机流,例如:
您可以使用 Monkey 以随机但可重复的方式对您正在开发的应用程序进行压力测试。
还有 monkeyrunner 工具,它提供了一个 API,用于编写控制程序来自 Android 代码外部的 Android 设备或模拟器。使用monkeyrunner,您可以编写一个Python 程序来安装Android 应用程序或测试包、运行它、向其发送击键、获取其用户界面的屏幕截图并将屏幕截图存储在工作站上。
There is a tool that comes with the SDK called Monkey which generates pseudo-random streams of user events such as:
You can use the Monkey to stress-test applications that you are developing, in a random yet repeatable manner.
There is also the monkeyrunner tool which provides an API for writing programs that control an Android device or emulator from outside of Android code. With monkeyrunner, you can write a Python program that installs an Android application or test package, runs it, sends keystrokes to it, takes screenshots of its user interface, and stores screenshots on the workstation.
对于按下按钮,您可以使用以下命令:
可以在此处找到可用键码列表:
http://developer.android.com/reference/android/view/KeyEvent.html
对于触摸屏事件,您可以使用:
For button presses, you can use the following:
A list of available keycodes can be found here:
http://developer.android.com/reference/android/view/KeyEvent.html
For touchscreen events, you can use: