Use monkeyrunner (provided by the [Android SDK])(https://developer.android.com/sdk/installing/index.html?pkg=tools)
and run the script:
$ monkeyrunner clan-away.py
Use monkeyrunner (provided by the [Android SDK])(https://developer.android.com/sdk/installing/index.html?pkg=tools)
and run the script:
$ monkeyrunner clan-away.py
| from __future__ import division | |
| from random import randint | |
| #!/usr/bin/python | |
| from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice | |
| from math import log | |
| import time | |
| import commands | |
| import sys | |
| # module functions | |
| def xfrange(start, stop, step): | |
| old_start = start | |
| digits = int(round(log(10000, 10)))+1 | |
| magnitude = 10**digits | |
| stop = int(magnitude * stop) | |
| step = int(magnitude * step) | |
| if start == 0: | |
| start = 10**(digits-1) | |
| else: | |
| start = 10**(digits)*start | |
| data = [] | |
| end_loop = int((stop-start)//step) | |
| if old_start == 0: | |
| end_loop += 1 | |
| acc = start | |
| for i in xrange(0, end_loop): | |
| data.append(acc/magnitude) | |
| acc += step | |
| return data | |
| # module variables | |
| TL = [250, 250] # Co-Ordinates of Top Left Corner | |
| BR = [1600, 800] # Co-Ordinates of Bottom Right Corner | |
| count = 1000 # how many events to send | |
| delay = xfrange(1, 20, 0.01) # min & max delay between events | |
| # starting script | |
| print "Connecting to device..." | |
| # connection to the current device, and return a MonkeyDevice object | |
| device = MonkeyRunner.waitForConnection() | |
| time.sleep(2) | |
| print "Sending "+ str(count) +" events to device..." | |
| for event in range(0, count): | |
| # generate co-ords for event | |
| x = randint(TL[0], BR[0]) | |
| y = randint(TL[1], BR[1]) | |
| # delay for the configured amount of time | |
| d = delay[randint(0, len(delay)-1)] | |
| # sending an event which simulate a tap | |
| print "["+ str(event) +"] Touching (x: "+ str(x) + " y: "+ str(y) +") and waiting "+ str(d) +"secs" | |
| device.touch(x, y, MonkeyDevice.DOWN_AND_UP) | |
| # sleep for delay | |
| time.sleep(d) | |
| print "Completed sending events" |