import socket import os from multiprocessing import Process from tkinter import * from pynput import keyboard from pynput.mouse import Button, Controller from pynput import mouse # ipFile = open("IP.txt") # IP = ipFile.read() # ipFile.close() import threading # https://docs.python.org/3/library/threading.html import queue # # window = Tk() # label = Label(window, text= 'What is the IP') # entry = Entry(window, width=200) # entry.insert(END, IP) # label.pack() # entry.pack() MOUSE = Controller() dataToSend = "" SEPARATOR = "" BUFFER_SIZE = 128 # send 4096 bytes each time step host = "123.123.123.123" # the ip address or hostname of the server, the receiver # the port, let's use 5001 port = 5001 # create the client socket s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) print(f"[+] Connecting to {host}:{port}") s.connect((host, port)) print("[+] Connected.") # ----------------------------------------------------------- def on_press(key): dataToSend = "KP" dataToSend = dataToSend + (('{}'.format(key)).replace("'", "")) dataToSendBytes = dataToSend.encode() s.sendall(dataToSendBytes) def on_release(key): dataToSend = "KR" dataToSend = dataToSend + (('{}'.format(key)).replace("'", "")) dataToSendBytes = dataToSend.encode() s.sendall(dataToSendBytes) def on_click(x, y, button, pressed): if button == Button.left: dataToSend = ("ML") else: dataToSend = ("MR") dataToSend = dataToSend + str(x) + "," + str(y) dataToSendBytes = dataToSend.encode() s.sendall(dataToSendBytes) def mouseThread(): with mouse.Listener(on_click=on_click) as mouseListener: mouseListener.join() threading.Thread(target=mouseThread).start() with keyboard.Listener(on_press=on_press, on_release=on_release) as keyListener: keyListener.join()