Skip to content

Instantly share code, notes, and snippets.

@aniljava
Created July 24, 2016 17:03
Show Gist options
  • Save aniljava/e62a5aaad0e4e5808196cf83fc6f95ce to your computer and use it in GitHub Desktop.
Save aniljava/e62a5aaad0e4e5808196cf83fc6f95ce to your computer and use it in GitHub Desktop.
#!/usr/bin/env python2
import os
import sys
import commands
import time
import threading
origin_x = 100
origin_y = 600
DURATION = 50
import sys,tty,termios
class _Getch:
def __call__(self):
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
try:
tty.setraw(sys.stdin.fileno())
ch = sys.stdin.read(3)
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
return ch
def walker():
while True:
time.sleep(3)
direction()
def main():
global direction
thread = threading.Thread(target=walker)
thread.start()
inkey = _Getch()
while True:
while(1):
k=inkey()
if k!='':break
if k=='\x1b[A':
up()
durection = up
elif k=='\x1b[B':
down()
direction = down
elif k=='\x1b[C':
right()
direction = right
elif k=='\x1b[D':
left()
direction = left
else:
print "not an arrow key!"
direction = noop
print k, 'PRESSED'
def noop():
time.sleep(1)
def up():
x1 = origin_x
y1 = origin_y
x2 = 100
y2 = 625
move(x1,y1,x2,y2,DURATION)
def right():
x1 = origin_x + 50
y1 = origin_y + 20
x2 = origin_x + 150
y2 = origin_y + 40
move(x1,y1,x2,y2,DURATION)
def left():
x1 = origin_x - 20
y1 = origin_y - 20
x2 = origin_x
y2 = origin_y
move(x1,y1,x2,y2,DURATION)
def down():
x1 = origin_x + 0
y1 = origin_y - 0
x2 = origin_x + 20
y2 = origin_y - 40
move(x1,y1,x2,y2,DURATION)
def move(x1,y1, x2,y2, duration):
execute('adb shell input swipe {} {} {} {} {}'.format(x1,y1, x2,y2, duration))
direction = up
def execute(command):
try:
commands.getstatusoutput(command)
except:
pass
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment