Skip to content

Instantly share code, notes, and snippets.

@toshinarin
Last active August 29, 2015 14:12
Show Gist options
  • Save toshinarin/7beb00b7dcda6b31513a to your computer and use it in GitHub Desktop.
Save toshinarin/7beb00b7dcda6b31513a to your computer and use it in GitHub Desktop.
Android monkeyrunnerで特定の箇所をタップし続ける
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
import signal
import sys
import random
shouldQuit = False
shouldSkip = False
def signal_int_handler(signal, frame):
global shouldQuit
shouldQuit = True
print 'You pressed Ctrl+C! please wait to quit...'
def signal_stp_handler(signal, frame):
global shouldSkip
shouldSkip = not(shouldSkip)
print 'You pressed Ctrl+Z! shouldSkip: ' + str(shouldSkip)
signal.signal(signal.SIGINT, signal_int_handler)
signal.signal(signal.SIGTSTP, signal_stp_handler)
print "waiting device..."
device = MonkeyRunner.waitForConnection()
MonkeyRunner.sleep(1)
device.touch(1700, 180, "DOWN_AND_UP")
MonkeyRunner.sleep(1)
print 'Press Ctrl+C to quit'
touchCount = 1
while True:
waitTime = random.uniform(15,18)
if shouldQuit:
break
if shouldSkip:
print 'skip. waiting ' + str(waitTime) + 'sec...'
MonkeyRunner.sleep(waitTime)
continue
print 'touch ' + str(touchCount) + '. waiting ' + str(waitTime) + 'sec...'
touchCount += 1
device.touch(1700, 180, "DOWN_AND_UP")
MonkeyRunner.sleep(waitTime)
print "finish"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment