Skip to content

Instantly share code, notes, and snippets.

@ggirou
Last active July 3, 2017 19:39
Show Gist options
  • Save ggirou/e4447f0d9525e65b3d152c5daf568f95 to your computer and use it in GitHub Desktop.
Save ggirou/e4447f0d9525e65b3d152c5daf568f95 to your computer and use it in GitHub Desktop.
Android monkeyrunner
#!/bin/bash
# fswatch script.py | xargs -n1 ./run.sh
monkeyrunner < script.py
from time import time
# from threading import Timer
# from sched import scheduler
# Imports the monkeyrunner modules used by this program
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
# Connects to the current device, returning a MonkeyDevice object
device = MonkeyRunner.waitForConnection()
def tap(t):
device.touch(500, 500, 'UP')
def warmUp():
tap(0)
MonkeyRunner.sleep(3)
def tapAt(t):
MonkeyRunner.sleep(start + t - time())
tap(t)
print "%s - %s" % (t, time() - start)
# sum += start + t - time()
# count += + 1
# s.enter(t, 1, tap, [t])
def tapAtFor(t, wait):
i = 0
while i < wait:
tapAt(t + i)
i = i + 0.2
def b72_2152():
global start
start = time()
tapAt(0.5) # "Start"
tapAtFor(0.785, 0.4) # "Right corner"
tapAtFor(2.1, 0.8) # "Left corner"
tapAtFor(4, 0.8) # Right corner
tapAtFor(5.52, 0.8) # Left corner
tapAtFor(8.3, 0.4) # Stay Right corner
tapAtFor(9.69, 2) # Left corner and so on
MonkeyRunner.sleep(2)
def b72_v1():
global start
start = time()
# "First part"
tapAt(0.1)
tapAtFor(0.382, 2.5)
tapAt(5)
# "Second part"
tapAt(7)
tapAtFor(7.845, 1)
def b72_v2():
global start
start = time()
tapAt(0.5) # "Start"
tapAtFor(0.785, 0.4) # "Right corner"
tapAt(2.2) # "Left corner"
tapAtFor(3, 0.8) # "Left corner"
MonkeyRunner.sleep(4)
def b72_v3():
global start
start = time()
tapAt(0.5) # "Start"
tapAt(0.9) # "First jump"
tapAtFor(4, 0.4) # "Right corner"
tapAt(5.4) # Left corner
tapAt(6) # Left corner
tapAtFor(8, 0.4) # "Right corner"
tapAt(9.3) # Left corner
tapAt(9.9) # Left corner
tapAtFor(12, 0.4) # "Right corner"
tapAt(14.2) # "Left corner"
tapAt(14.6) # "Left corner"
tapAt(15.25) # "Left corner"
MonkeyRunner.sleep(4)
def b63_3464():
global start
start = time()
tapAt(0.5) # "Start"
tapAt(1.05) # "First Jumps"
tapAt(1.71) # "First Jumps"
tapAt(2.2) # "First Jumps"
MonkeyRunner.sleep(4)
def b89_v1():
global start
start = time()
tapAt(0.5) # "Start"
tapAtFor(0.9, 1.2) # "First Jumps"
tapAtFor(3.18, 1) # "Right corner"
tapAtFor(4.7, 2) # "Second Jump"
tapAtFor(8, 3) # "Second Jump"
MonkeyRunner.sleep(8)
# Continue...
def b89_v2():
global start
start = time()
tapAt(0.5) # "Start"
tapAtFor(0.9, 1.2) # "First Jumps"
tapAtFor(3.172, 1) # "Right corner"
tapAtFor(4.7, 0.1) # "Second Jump"
tapAtFor(7, 1.5) # "Left corner"
MonkeyRunner.sleep(8)
# Continue...
def b89_v3():
global start
start = time()
tapAt(0.5) # "Start"
tapAtFor(0.9, 1.2) # "First Jumps"
tapAtFor(3.18, 1) # "Right corner"
tapAtFor(4.7, 0.1) # "Second Jump"
tapAt(7) # "Left corner"
tapAt(7.6) # "Left corner"
tapAt(8) # "Left corner"
tapAt(9) # "Left corner"
tapAt(10) # "Left corner"
tapAtFor(10.7, 0.8) # "Left corner"
MonkeyRunner.sleep(8)
def b10_v1():
global start
start = time()
tapAtFor(0.5, 0.5) # "First Jumps"
tapAt(3.75) # "Jumps Ball 1"
tapAt(5.25) # "Jumps Ball 2"
tapAt(7) # "Jumps Ball 3"
tapAtFor(7.97, 1.5) # "Avoid RG"
tapAtFor(17.05, 0.4) # "Go right"
tapAt(18.35) # "Jump under RG"
tapAt(18.7) # "Top high jump"
tapAt(19.3) # "Jump left RG"
tapAt(20.25) # "Jump ball"
tapAtFor(21.0325, 0.8) # "Jump hole and saw"
MonkeyRunner.sleep(8)
def b10_v2():
global start
start = time()
tapAt(0.5) # Start
tapAt(1.17) # "First jump"
tapAt(1.785) # "Right jump"
tapAt(2.68) # "Jump RG & ball"
tapAt(4) # "Left jump"
tapAt(8.5) # "Go"
tapAtFor(8.85, 2.5) # "High jump & go"
tapAtFor(12.236, 0.75) # "saw jump"
MonkeyRunner.sleep(4)
def b67_v1():
global start
start = time()
tapAt(0.5) # Start
d = -0.22
tapAt(10 + d) # "First jump"
tapAt(11.03 + d) # "Angel jump"
tapAtFor(11.9, 0.5) # "Bottom corner"
tapAt(12.8) # "Wall jump"
MonkeyRunner.sleep(4)
device.wake()
# warmUp()
b89_v2()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment