我正在开发一个应用程序,它有adb控制台的定时控制。“adb shell sendevent”命令控制应用程序的触摸事件。但是这个触摸事件是定时的
import os
apkLocation = "/Users/siddharthan64/Desktop/adt/sdk/platform-tools/"
os.chdir(apkLocation)
cmdList = ['./adb shell sendevent /dev/input/event2: 3 53 251','./adb shell sendevent / dev/input/event2: 3 54 399','./adb shell sendevent /dev/input/event2: 3 48 10','./adb shell sendevent /dev/input/event2: 3 50 7','./adb shell sendevent /dev/input/event2: 0 2 0']
cmdList.append['./adb shell sendevent /dev/input/event2: 3 50 7']
cmdList.append[,'./adb shell sendevent /dev/input/event2: 0 2 0']
cmdList.append['./adb shell sendevent /dev/input/event2: 0 0 0']
cmdList.append['./adb shell sendevent /dev/input/event2: 3 57 0']
cmdList.append['./adb shell sendevent /dev/input/event2: 3 53 251']
cmdList.append['./adb shell sendevent /dev/input/event2: 3 54 399']
cmdList.append['./adb shell sendevent /dev/input/event2: 3 48 0']
cmdList.append['./adb shell sendevent /dev/input/event2: 3 50 0']
cmdList.append['./adb shell sendevent /dev/input/event2: 0 2 0']
cmdList.append['./adb shell sendevent /dev/input/event2: 0 0 0']
for tcmd in cmdList:
p = os.popen(tcmd,"r")
在应用程序上发生特定事件时发送。在
实际上,
sendevent
因设备而异。这是我个人的经验。如果您试图模拟触摸事件,那么您可以在Android中使用Instrumentation
的概念。在因此,您需要一个
BroadcastReceiver
从adb
外壳接收输入触摸坐标。在下面是
BroadcastReceiver
的代码,该代码具有检测代码:您需要在
^{pr2}$manifest
中注册您的BroadcastReceiver
,如下所示:应用程序启动后,以调试模式连接设备,在命令提示符下输入以下命令:
上面的命令将触发应用程序的
BroadcstReceiver
,并在坐标(10,20)处模拟触摸。可以将其替换为所需的值。在注意:如果应用程序被最小化,并且您试图模拟触摸事件,则该应用程序将强制关闭,因为android开发者限制了这一未来,因为它很容易被黑客滥用。在
相关问题 更多 >
编程相关推荐