Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Automate the tapping of the beast in Monolith by using Android's MonkeyRunner
#! /usr/bin/env monkeyrunner
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
import sys
import signal
import random
# Automate the tapping of the beast in [Monolith](https://play.google.com/store/apps/details?id=com.cac.monolith)
# by using MonkeyRunner.
#
# Read the instructions for setting it up here:
# http://flyingtophat.co.uk/blog/2015/08/03/conquering-the-monolith-beast-with-android-monkeyrunner.html
#
# ##### "Tapping is so Middle Ages!"
# ##### -- Monolith
# #####
# #####
__author__ = 'Lucas'
__homepage__ = 'http://www.flyingtophat.co.uk/'
__version__ = '1.0'
__date__ = '2015/08/03'
device = None
def execute():
print "Connecting to device..."
device = MonkeyRunner.waitForConnection()
print "Connected"
tap_positions = [[200, 400], [300, 410]]
tap_sleep_time = 0.09
old_phone_rest_time = 5
old_phone_sleep_interval = 1000
old_phone_sleep_counter = 0
print "Tapping..."
while True:
for tap_position in tap_positions:
device.touch(tap_position[0] + random.randint(1, 20),
tap_position[1] + random.randint(1, 20),
'UP')
MonkeyRunner.sleep(tap_sleep_time)
old_phone_sleep_counter += 1
if old_phone_sleep_counter == old_phone_sleep_interval:
print "Letting my old phone have a %s second rest" % old_phone_rest_time
MonkeyRunner.sleep(old_phone_rest_time)
old_phone_sleep_counter = 0
def exit_gracefully(signum, frame):
print "Gracefully exiting"
signal.signal(signal.SIGINT, signal.getsignal(signal.SIGINT))
if device is not None:
device.shell('killall com.android.commands.monkey')
sys.exit(1)
if __name__ == '__main__':
signal.signal(signal.SIGINT, exit_gracefully)
execute()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment