d_str)
? ? ? ? ? ? # up
? ? ? ? ? ? cmd_str = ''
? ? ? ? ? ? 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)
? ? ? ? ? ? if DEBUG:
? ? ? ? ? ? ? ? print cmd_str
? ? ? ? ? ? adbshellcommand(cmd_str)
# Framebuffer Class
# Only record framebuffer attributs
class fb:
? ? fb_bpp = 0
? ? fb_size = 0
? ? fb_width = 0
? ? fb_height = 0
? ? red_offset = 0
? ? red_length = 0
? ? blue_offset = 0
? ? blue_length = 0
? ? green_offset = 0
? ? green_length = 0
? ? alpha_offset = 0
? ? alpha_length = 0
? ? fb_data = None
? ? def __init__(self):
? ? ? ? fb_bpp = 0
? ? ? ? fb_size = 0
? ? ? ? fb_width = 0
? ? ? ? fb_height = 0
? ? ? ? red_offset = 0
? ? ? ? red_length = 0
? ? ? ? blue_offset = 0
? ? ? ? blue_length = 0
? ? ? ? green_offset = 0
? ? ? ? green_length = 0
? ? ? ? alpha_offset = 0
? ? ? ? alpha_length = 0
? ? ? ? fb_data = None
# send key thread
class send_key_thread(threading.Thread):
? ? __tkapp = None
? ? __root = None
? ? __key = None
? ?
? ? def __init__(self, key):
? ? ? ? if DEBUG:
? ? ? ? ? ? print 'send_key_thread init'
? ? ? ? threading.Thread.__init__(self)
? ? ? ? self.thread_stop = False
? ? ? ? self.__key = key
? ? def devexist(self):
? ? ? ? p = subprocess.Popen("adb devices", shell=True, stdout=subprocess.PIPE)
? ? ? ? p.wait()
? ? ? ? devList = p.communicate()
? ? ? ? devList = devList[0].splitlines()
? ? ? ? if 'device' in devList[1]:
? ? ? ? ? ? if DEBUG:
? ? ? ? ? ? ? ? print devList[1]
? ? ? ? ? ? return True
? ? ? ? else:
? ? ? ? ? ? if DEBUG:
? ? ? ? ? ? ? ? print 'No adb device found'
? ? ? ? ? ? return False
? ? def sendKey(self):
? ? ? ? if DEBUG:
? ? ? ? ? ? print 'send_key: %s' % self.__key
? ? ? ? if self.__key in keynames:
? ? ? ? ? ? if self.devexist():
? ? ? ? ? ? ? ? if self.__key != 'none':
? ? ? ? ? ? ? ? ? ? adbshellcommand('input keyevent %s' % str(keyvalues[keynames.index(self.__key)]))
? ? def run(self):
? ? ? ? if DEBUG:
? ? ? ? ? ? print 'send_key_thread run'
? ? ? ? self.sendKey()
? ? def stop(self):
? ? ? ? if DEBUG:
? ? ? ? ? ? print 'stop send_key_thread'
? ? ? ? self.thread_stop = True
# Kaypad Tkinter-Based GUI application
class KeypadApplication(tk.Frame):
? ? def __init__(self, master=None):
? ? ? ? if master == None:
? ? ? ? ? ? master = tk.Tk()
? ? ? ? tk.Frame.__init__(self, master, class_='KeypadApplication')
? ? ? ? self.createkeypad()
? ? ? ? self.grid()
? ? def createkeypad(self):
? ? ? ? # creat buttons from keymap with 4 buttons each row
? ? ? ? for btn_name in keynames:
? ? ? ? ? ? row_id = keynames.index(btn_name) / 4
? ? ? ? ? ? col_id = keynames.index(btn_name) % 4
? ? ? ? ? ? if btn_name != 'none':
? ? ? ? ? ? ? ? self.tbutton = tk.Button(self, name = btn_name, text=btn_name)
? ? ? ? ? ? ? ? self.tbutton['activebackground'] = '#BBBBBB'
? ? ? ? ? ? ? ? #self.tbutton['highlightcolor'] = '#BBBB00'
? ? ? ? ? ? else:
? ? ? ? ? ? ? ? self.tbutton = tk.Button(self, name = btn_name, text='')
? ? ? ? ? ? self.tbutton['width'] = 10
? ? ? ? ? ? if btn_name != 'none':
? ? ? ? ? ? ? ? self.tbutton.bind('', self.sendKey)
? ? ? ? ? ? ? ? self.tbutton.grid(padx = 5, pady = 1, column = col_id, row = row_id)
? ? def devexist(self):
? ? ? ? p = subprocess.Popen("adb devices", shell=True, stdout=subprocess.PIPE)
? ? ? ? p.wait()
? ? ? ? devList = p.communicate()
? ? ? ? devList = devList[0].splitlines()
? ? ? ? if 'device' in devList[1]:
? ? ? ? ? ? if DEBUG:
? ? ? ? ? ? ? ? print devList[1]
? ? ? ? ? ? return True
? ? ? ? else:
? ? ? ? ? ? if DEBUG:
? ? ? ? ? ? ? ? print 'No adb device found'
? ? ? ? ? ? return False
? ? def sendKey(self, event=None):
? ? ? ? if DEBUG:
? ? ? ? ? ? print event.widget.winfo_name()
? ? ? ? keyname = event.widget.winfo_name()
? ? ? ? if keyname in keynames:
? ? ? ? ? ? sender = send_key_thread(keyname