Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import subprocess
- import os
- import re
- class keyevent:
- direction = ""
- x = ""
- y = ""
- time = ""
- def __init__(self, directionInput, xInput, yInput,timeInput):
- self.direction = directionInput
- self.x = xInput
- self.y = yInput
- self.time = timeInput
- def setDir():
- os.chdir("/platform-tools")
- def getDevices():
- sProcess = subprocess.Popen(["adb", "devices"], stdout=subprocess.PIPE)
- output = sProcess.communicate()[0]
- output = str(output)
- test = []
- test = output.split('\\n')
- return test
- def printOutput(functionInput):
- for i in functionInput:
- i = i.replace('\\r', ' ')
- i = i.replace('\\t', " ")
- print(i)
- def pressHomeKey():
- sProcess = subprocess.Popen(["adb", "shell", "input", "keyevent", "3"], stdout=subprocess.PIPE)
- output = sProcess.communicate()[0]
- def getEnv():
- sProcess = subprocess.Popen(["adb", "shell", "getevent", "-tld", "/dev/input/event10"], stdout=subprocess.PIPE)
- output = sProcess.communicate()[0]
- output = str(output)
- test = []
- test = output.split('\\n')
- return test
- def createEventList(functionInput):
- indexOfButtonPresses = []
- realListOfButtons = []
- for index, item in enumerate(functionInput):
- if(item.find("BTN_TOUCH") > 0):
- indexOfButtonPresses.append(functionInput[index])
- if(item.find("ABS_MT_POSITION_X") > 0):
- indexOfButtonPresses.append(functionInput[index])
- if(item.find("ABS_MT_POSITION_Y") > 0):
- indexOfButtonPresses.append(functionInput[index])
- for newIndex, i in enumerate(indexOfButtonPresses):
- if(i.find("DOWN") > 0):
- realListOfButtons.append(indexOfButtonPresses[newIndex-2])
- realListOfButtons.append(indexOfButtonPresses[newIndex-1])
- realListOfButtons.append(indexOfButtonPresses[newIndex])
- if(i.find("UP") > 0):
- realListOfButtons.append(indexOfButtonPresses[newIndex-2])
- realListOfButtons.append(indexOfButtonPresses[newIndex-1])
- realListOfButtons.append(indexOfButtonPresses[newIndex])
- return realListOfButtons
- def regexList(functionInput):
- returnObject = []
- for i in functionInput:
- matchObject = re.search(r'(\[\s\s\d*.\d*\]).*([_][X]|[_][Y]|[B][T][N]).*(\S{8}|[D]...|[U].)', i)
- returnObject.append(matchObject)
- return returnObject
- def parseList(functionInput):
- returnObject = []
- for i in functionInput:
- x = ""
- y = ""
- direction = ""
- time = ""
- if(y == "" and i.group(2) == "_Y"):
- y = i.group(3)
- if(x == "" and i.group(2) == "_X"):
- x = i.group(3)
- if(direction == "" and i.group(3) == "UP" or i.group(3) == "DOWN"):
- direction = i.group(3)
- time = i.group(1)
- tempEvent = keyevent(direction,x,y,time)
- returnObject.append(tempEvent)
- x = ""
- y = ""
- direction = ""
- time = ""
- return returnObject
- setDir()
- printOutput(getDevices())
- pressHomeKey()
- outputTest = getEnv()
- eventList = createEventList(outputTest)
- matches = regexList(eventList)
- parseMatches = parseList(matches)
- for i in parseMatches:
- print(i.x)
- print(i.y)
- print(i.direction)
- print(i.time)
- print("==================")
Advertisement
Add Comment
Please, Sign In to add comment