我想将鼠标事件注入正在运行的应用程序(例如单击并移动鼠标指针)。猴子工具有可能吗?如果是的话,你能给我一个关于如何在Android应用程序开发平台中使用猴子工具的路线图吗?
答案 0 :(得分:0)
我正在使用Monkey在模拟器中驱动应用程序。
我有一个Python脚本可以提供给monkeyrunner工具。这主要来自Android开发人员website上的示例。 可以调用活动并对其进行响应。 例如,我在这里调用一个活动,然后又运行另一个活动;在那一点上,我输入4位数字并“点击”屏幕上与'ok'按钮对应的坐标100,400。
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
if __name__ == "__main__":
# Connects to the current device, returning a MonkeyDevice object
device = MonkeyRunner.waitForConnection()
# Installs the Android package. Notice that this method returns a boolean, so you can test
# to see if the installation worked.
# device.installPackage('myproject/bin/MyApplication.apk')
# sets a variable with the package's internal name
package = 'com.mypackage'
# sets a variable with the name of an Activity in the package
activity = 'com.mypackage.myactivity'
# sets the name of the component to start
runComponent = package + '/' + activity
# Runs the component
device.startActivity(component=runComponent)
if device.getProperty('am.current.comp.class') == 'com.mypackage.anotheractivity':
device.type('0000')
# Click the 'Enter' button on screen at coordinates 100,400
device.touch(100, 600, 'DOWN_AND_UP')
我希望有所帮助。