wheelsmanx

ADB SHELL GETEVENT LIST

Apr 5th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.40 KB | None | 0 0
  1. import subprocess
  2. import os
  3. import re
  4.  
  5.  
  6. class keyevent:
  7. direction = ""
  8. x = ""
  9. y = ""
  10. time = ""
  11.  
  12. def __init__(self, directionInput, xInput, yInput,timeInput):
  13. self.direction = directionInput
  14. self.x = xInput
  15. self.y = yInput
  16. self.time = timeInput
  17.  
  18.  
  19.  
  20.  
  21.  
  22. def setDir():
  23. os.chdir("/platform-tools")
  24.  
  25.  
  26. def getDevices():
  27. sProcess = subprocess.Popen(["adb", "devices"], stdout=subprocess.PIPE)
  28. output = sProcess.communicate()[0]
  29. output = str(output)
  30. test = []
  31. test = output.split('\\n')
  32. return test
  33.  
  34.  
  35. def printOutput(functionInput):
  36. for i in functionInput:
  37. i = i.replace('\\r', ' ')
  38. i = i.replace('\\t', " ")
  39. print(i)
  40.  
  41. def pressHomeKey():
  42. sProcess = subprocess.Popen(["adb", "shell", "input", "keyevent", "3"], stdout=subprocess.PIPE)
  43. output = sProcess.communicate()[0]
  44.  
  45.  
  46. def getEnv():
  47. sProcess = subprocess.Popen(["adb", "shell", "getevent", "-tld", "/dev/input/event10"], stdout=subprocess.PIPE)
  48. output = sProcess.communicate()[0]
  49. output = str(output)
  50. test = []
  51. test = output.split('\\n')
  52. return test
  53.  
  54. def createEventList(functionInput):
  55. indexOfButtonPresses = []
  56. realListOfButtons = []
  57. for index, item in enumerate(functionInput):
  58. if(item.find("BTN_TOUCH") > 0):
  59. indexOfButtonPresses.append(functionInput[index])
  60. if(item.find("ABS_MT_POSITION_X") > 0):
  61. indexOfButtonPresses.append(functionInput[index])
  62. if(item.find("ABS_MT_POSITION_Y") > 0):
  63. indexOfButtonPresses.append(functionInput[index])
  64. for newIndex, i in enumerate(indexOfButtonPresses):
  65. if(i.find("DOWN") > 0):
  66. realListOfButtons.append(indexOfButtonPresses[newIndex-2])
  67. realListOfButtons.append(indexOfButtonPresses[newIndex-1])
  68. realListOfButtons.append(indexOfButtonPresses[newIndex])
  69. if(i.find("UP") > 0):
  70. realListOfButtons.append(indexOfButtonPresses[newIndex-2])
  71. realListOfButtons.append(indexOfButtonPresses[newIndex-1])
  72. realListOfButtons.append(indexOfButtonPresses[newIndex])
  73. return realListOfButtons
  74.  
  75. def regexList(functionInput):
  76. returnObject = []
  77. for i in functionInput:
  78. matchObject = re.search(r'(\[\s\s\d*.\d*\]).*([_][X]|[_][Y]|[B][T][N]).*(\S{8}|[D]...|[U].)', i)
  79. returnObject.append(matchObject)
  80. return returnObject
  81.  
  82. def parseList(functionInput):
  83. returnObject = []
  84. for i in functionInput:
  85. x = ""
  86. y = ""
  87. direction = ""
  88. time = ""
  89. if(y == "" and i.group(2) == "_Y"):
  90. y = i.group(3)
  91. if(x == "" and i.group(2) == "_X"):
  92. x = i.group(3)
  93. if(direction == "" and i.group(3) == "UP" or i.group(3) == "DOWN"):
  94. direction = i.group(3)
  95. time = i.group(1)
  96. tempEvent = keyevent(direction,x,y,time)
  97. returnObject.append(tempEvent)
  98. x = ""
  99. y = ""
  100. direction = ""
  101. time = ""
  102. return returnObject
  103. setDir()
  104. printOutput(getDevices())
  105. pressHomeKey()
  106. outputTest = getEnv()
  107.  
  108. eventList = createEventList(outputTest)
  109. matches = regexList(eventList)
  110. parseMatches = parseList(matches)
  111. for i in parseMatches:
  112. print(i.x)
  113. print(i.y)
  114. print(i.direction)
  115. print(i.time)
  116. print("==================")
Advertisement
Add Comment
Please, Sign In to add comment