# Find the Touch input device and event
def get_touch_event():
tp_names = ['ft5x06', 'gt818']
output = adbshellcommand('getevent -S')
if output == None:
return None
if DEBUG:
print output
dev = ''
name = ''
for line in output.splitlines():
if '/dev/input/event' in line:
line = line.split(':')
if len(line) == 2:
line = line[1]
line = line.strip(' ')
line = line.strip('"')
dev = line
elif 'name:' in line:
line = line.split(':')
if len(line) == 2:
line = line[1]
line = line.strip(' ')
line = line.strip('"')
name = line
if (dev != '') and (name in tp_names):
break
if DEBUG:
print '%s : %s' % (name, dev)
if name in tp_names:
return (name, dev)
else:
return None
# Do the touch action
def send_touch_event(action, x0, y0, x1 = None, y1 = None):
# Note: input support tap & swipe after 4.1
# so we need emulate TP via sendevent if tap or swipe fail
if action == 'tap':
resp = adbshellcommand('input tap %d %d' % (x0, y0))
if 'Error' in resp:
print 'Not support tap command'
# get tp device
tp = get_touch_event()
if tp == None:
return
# down
cmd_str = ''
cmd_str = cmd_str + 'sendevent %s %d %d %d;' % (tp[1], 3, 53, x0)
cmd_str = cmd_str + 'sendevent %s %d %d %d;' % (tp[1], 3, 54, y0)
cmd_str = cmd_str + 'sendevent %s %d %d %d;' % (tp[1], 3, 57, 0)
cmd_str = cmd_str + 'sendevent %s %d %d %d;' % (tp[1], 3, 48, 0)
cmd_str = cmd_str + 'sendevent %s %d %d %d;' % (tp[1], 0, 2, 0)
cmd_str = cmd_str + 'sendevent %s %d %d %d;' % (tp[1], 1, 330, 1)
cmd_str = cmd_str + 'sendevent %s %d %d %d;' % (tp[1], 0, 0, 0)
# up
cmd_str = cmd_str + 'sendevent %s %d %d %d;' % (tp[1], 1, 330, 0)
cmd_str = cmd_str + 'sendevent %s %d %d %d;' % (tp[1], 0, 2, 0)
cmd_str = cmd_str + 'sendevent %s %d %d %d;' % (tp[1], 0, 0, 0)