Merge pull request 'Remove tqdm from the scripts' (#3) from no_tqdm into master

Reviewed-on: https://gitea.doserver.duckdns.org/CactiChameleon9/Remote_Control_Python_Script/pulls/3
This commit is contained in:
CactiChameleon9 2020-12-10 16:19:25 +00:00
commit b475adef12
8 changed files with 261 additions and 292 deletions

View File

@ -1,11 +1,11 @@
import socket import socket
import os import os
import tqdm
# device's IP address # device's IP address
SERVER_HOST = "127.0.0.1" #(socket.gethostbyname(socket.gethostname())) SERVER_HOST = "127.0.0.1" #(socket.gethostbyname(socket.gethostname()))
SERVER_PORT = 5001 SERVER_PORT = 5001
# receive 4096 bytes each time # receive 4096 bytes each time
BUFFER_SIZE = 4096 BUFFER_SIZE = 128
SEPARATOR = "<SEPARATOR>" SEPARATOR = "<SEPARATOR>"
# create the server socket # create the server socket
# TCP socket # TCP socket
@ -31,24 +31,22 @@ filename = os.path.basename(filename)
filesize = int(filesize) filesize = int(filesize)
# start receiving the file from the socket # start receiving the file from the socket
# and writing to the file stream # and writing to the file stream
progress = tqdm.tqdm(range(filesize), f"Receiving {filename}", unit="B", unit_scale=True, unit_divisor=1024)
#with open(filename, "wb") as f: #with open(filename, "wb") as f:
while True: while True:
for _ in progress: # read 1024 bytes from the socket (receive)
# read 1024 bytes from the socket (receive) bytes_read = client_socket.recv(BUFFER_SIZE)
bytes_read = client_socket.recv(BUFFER_SIZE) if not bytes_read:
if not bytes_read: # nothing is received
# nothing is received # file transmitting is done take another time
# file transmitting is done take another time break
break # write to the file the bytes we just received
# write to the file the bytes we just received f = open(filename, 'ab')
f = open(filename, 'ab') if (bytes_read.find("Key") == -1): #don't write shifts and controls
f.write(bytes_read) f.write(bytes_read)
print(bytes_read) print(bytes_read)
# update the progress bar f.close()
progress.update(len(bytes_read))
f.close()
# close the client socket # close the client socket
#client_socket.close() #client_socket.close()

View File

@ -1,6 +1,5 @@
import socket import socket
import os import os
import tqdm
import pynput import pynput
from pynput.keyboard import Key, Controller from pynput.keyboard import Key, Controller
#press #press
@ -36,118 +35,115 @@ filename = os.path.basename(filename)
filesize = int(filesize) filesize = int(filesize)
# start receiving the file from the socket # start receiving the file from the socket
# and writing to the file stream # and writing to the file stream
progress = tqdm.tqdm(range(filesize), f"Receiving {filename}", unit="B", unit_scale=True, unit_divisor=1024)
#with open(filename, "wb") as f: #with open(filename, "wb") as f:
def pressRrelease_char(char): def pressRrelease_char(char):
keyboard.press(char) keyboard.press(char)
while True: while True:
for _ in progress: # read 1024 bytes from the socket (receive)
# read 1024 bytes from the socket (receive) bytes_read = client_socket.recv(BUFFER_SIZE)
bytes_read = client_socket.recv(BUFFER_SIZE) if not bytes_read:
if not bytes_read: # nothing is received
# nothing is received # file transmitting is done take another time
# file transmitting is done take another time break
break # write to the file the bytes we just received
# write to the file the bytes we just received f = open(filename, 'wb')
f = open(filename, 'wb') f.write(bytes_read)
f.write(bytes_read) # update the progress bar
# update the progress bar f.close()
progress.update(len(bytes_read))
f.close()
g = open(filename, 'r') g = open(filename, 'r')
ge = g.read() ge = g.read()
print (ge) print (ge)
try: try:
if (ge == "Key.enter"): if (ge == "Key.enter"):
pressRrelease_char(Key.enter) pressRrelease_char(Key.enter)
elif (ge == "Key.shift"): elif (ge == "Key.shift"):
pressRrelease_char(Key.shift) pressRrelease_char(Key.shift)
elif (ge == "Key.space"): elif (ge == "Key.space"):
pressRrelease_char(Key.space) pressRrelease_char(Key.space)
elif (ge == "Key.backspace"): elif (ge == "Key.backspace"):
pressRrelease_char(Key.backspace) pressRrelease_char(Key.backspace)
elif (ge == "Key.ctrl_r"): elif (ge == "Key.ctrl_r"):
pressRrelease_char(Key.ctrl_r) pressRrelease_char(Key.ctrl_r)
elif (ge == "Key.ctrl_l"): elif (ge == "Key.ctrl_l"):
pressRrelease_char(Key.ctrl_l) pressRrelease_char(Key.ctrl_l)
elif (ge == "Key.shift_r"): elif (ge == "Key.shift_r"):
pressRrelease_char(Key.shift_r) pressRrelease_char(Key.shift_r)
elif (ge == "Key.alt_l"): elif (ge == "Key.alt_l"):
pressRrelease_char(Key.alt_l) pressRrelease_char(Key.alt_l)
elif (ge == "Key.alt_r"): elif (ge == "Key.alt_r"):
pressRrelease_char(Key.alt_r) pressRrelease_char(Key.alt_r)
elif (ge == "Key.cmd"): elif (ge == "Key.cmd"):
pressRrelease_char(Key.cmd) pressRrelease_char(Key.cmd)
elif (ge == "Key.caps_lock"): elif (ge == "Key.caps_lock"):
pressRrelease_char(Key.caps_lock) pressRrelease_char(Key.caps_lock)
elif (ge == "Key.tab"): elif (ge == "Key.tab"):
pressRrelease_char(Key.tab) pressRrelease_char(Key.tab)
elif (ge == "Key.f1"): elif (ge == "Key.f1"):
pressRrelease_char(Key.f1) pressRrelease_char(Key.f1)
elif (ge == "Key.f2"): elif (ge == "Key.f2"):
pressRrelease_char(Key.f2) pressRrelease_char(Key.f2)
elif (ge == "Key.f3"): elif (ge == "Key.f3"):
pressRrelease_char(Key.f3) pressRrelease_char(Key.f3)
elif (ge == "Key.f4"): elif (ge == "Key.f4"):
pressRrelease_char(Key.f4) pressRrelease_char(Key.f4)
elif (ge == "Key.f5"): elif (ge == "Key.f5"):
pressRrelease_char(Key.f5) pressRrelease_char(Key.f5)
elif (ge == "Key.f6"): elif (ge == "Key.f6"):
pressRrelease_char(Key.f6) pressRrelease_char(Key.f6)
elif (ge == "Key.f7"): elif (ge == "Key.f7"):
pressRrelease_char(Key.f7) pressRrelease_char(Key.f7)
elif (ge == "Key.f8"): elif (ge == "Key.f8"):
pressRrelease_char(Key.f8) pressRrelease_char(Key.f8)
elif (ge == "Key.f9"): elif (ge == "Key.f9"):
pressRrelease_char(Key.f9) pressRrelease_char(Key.f9)
elif (ge == "Key.f10"): elif (ge == "Key.f10"):
pressRrelease_char(Key.f10) pressRrelease_char(Key.f10)
elif (ge == "Key.f11"): elif (ge == "Key.f11"):
pressRrelease_char(Key.f11) pressRrelease_char(Key.f11)
elif (ge == "Key.f12"): elif (ge == "Key.f12"):
pressRrelease_char(Key.f12) pressRrelease_char(Key.f12)
elif (ge == "Key.esc"): elif (ge == "Key.esc"):
pressRrelease_char(Key.esc) pressRrelease_char(Key.esc)
elif (ge == "Key.insert"): elif (ge == "Key.insert"):
pressRrelease_char(Key.insert) pressRrelease_char(Key.insert)
elif (ge == "Key.delete"): elif (ge == "Key.delete"):
pressRrelease_char(Key.delete) pressRrelease_char(Key.delete)
elif (ge == "Key.end"): elif (ge == "Key.end"):
pressRrelease_char(Key.end) pressRrelease_char(Key.end)
elif (ge == "Key.num_lock"): elif (ge == "Key.num_lock"):
pressRrelease_char(Key.num_lock) pressRrelease_char(Key.num_lock)
elif (ge == "Key.home"): elif (ge == "Key.home"):
pressRrelease_char(Key.home) pressRrelease_char(Key.home)
elif (ge == "Key.page_up"): elif (ge == "Key.page_up"):
pressRrelease_char(Key.page_up) pressRrelease_char(Key.page_up)
elif (ge == "Key.page_down"): elif (ge == "Key.page_down"):
pressRrelease_char(Key.page_down) pressRrelease_char(Key.page_down)
elif (ge == "Key.pause"): elif (ge == "Key.pause"):
pressRrelease_char(Key.pause) pressRrelease_char(Key.pause)
elif (ge == "Key.scroll_lock"): elif (ge == "Key.scroll_lock"):
pressRrelease_char(Key.scroll_lock) pressRrelease_char(Key.scroll_lock)
elif (ge == "Key.menu"): elif (ge == "Key.menu"):
pressRrelease_char(Key.menu) pressRrelease_char(Key.menu)
elif (ge == "Key.print_screen"): elif (ge == "Key.print_screen"):
pressRrelease_char(Key.print_screen) pressRrelease_char(Key.print_screen)
elif (ge == "Key.left"): elif (ge == "Key.left"):
pressRrelease_char(Key.left) pressRrelease_char(Key.left)
elif (ge == "Key.up"): elif (ge == "Key.up"):
pressRrelease_char(Key.up) pressRrelease_char(Key.up)
elif (ge == "Key.right"): elif (ge == "Key.right"):
pressRrelease_char(Key.right) pressRrelease_char(Key.right)
elif (ge == "Key.down"): elif (ge == "Key.down"):
pressRrelease_char(Key.down) pressRrelease_char(Key.down)
else: else:
pressRrelease_char((ge)) pressRrelease_char((ge))
except: except:
print("an error occured with ", ge) print("an error occured with ", ge)
g.close() g.close()

View File

@ -1,6 +1,5 @@
import socket import socket
import os import os
import tqdm
import pynput import pynput
from pynput.keyboard import Key, Controller from pynput.keyboard import Key, Controller
#release #release
@ -36,7 +35,6 @@ filename = os.path.basename(filename)
filesize = int(filesize) filesize = int(filesize)
# start receiving the file from the socket # start receiving the file from the socket
# and writing to the file stream # and writing to the file stream
progress = tqdm.tqdm(range(filesize), f"Receiving {filename}", unit="B", unit_scale=True, unit_divisor=1024)
#with open(filename, "wb") as f: #with open(filename, "wb") as f:
@ -44,110 +42,108 @@ def pressRrelease_char(char):
keyboard.release(char) keyboard.release(char)
while True: while True:
for _ in progress: # read 1024 bytes from the socket (receive)
# read 1024 bytes from the socket (receive) bytes_read = client_socket.recv(BUFFER_SIZE)
bytes_read = client_socket.recv(BUFFER_SIZE) if not bytes_read:
if not bytes_read: # nothing is received
# nothing is received # file transmitting is done take another time
# file transmitting is done take another time break
break # write to the file the bytes we just received
# write to the file the bytes we just received f = open(filename, 'wb')
f = open(filename, 'wb') f.write(bytes_read)
f.write(bytes_read)
# update the progress bar
progress.update(len(bytes_read))
f.close()
g = open(filename, 'r') f.close()
ge = g.read()
print (ge) g = open(filename, 'r')
try: ge = g.read()
if (ge == "Key.enter"):
pressRrelease_char(Key.enter) print (ge)
elif (ge == "Key.shift"): try:
pressRrelease_char(Key.shift) if (ge == "Key.enter"):
elif (ge == "Key.space"): pressRrelease_char(Key.enter)
pressRrelease_char(Key.space) elif (ge == "Key.shift"):
elif (ge == "Key.backspace"): pressRrelease_char(Key.shift)
pressRrelease_char(Key.backspace) elif (ge == "Key.space"):
elif (ge == "Key.ctrl_r"): pressRrelease_char(Key.space)
pressRrelease_char(Key.ctrl_r) elif (ge == "Key.backspace"):
elif (ge == "Key.ctrl_l"): pressRrelease_char(Key.backspace)
pressRrelease_char(Key.ctrl_l) elif (ge == "Key.ctrl_r"):
elif (ge == "Key.shift_r"): pressRrelease_char(Key.ctrl_r)
pressRrelease_char(Key.shift_r) elif (ge == "Key.ctrl_l"):
elif (ge == "Key.alt_l"): pressRrelease_char(Key.ctrl_l)
pressRrelease_char(Key.alt_l) elif (ge == "Key.shift_r"):
elif (ge == "Key.alt_r"): pressRrelease_char(Key.shift_r)
pressRrelease_char(Key.alt_r) elif (ge == "Key.alt_l"):
elif (ge == "Key.cmd"): pressRrelease_char(Key.alt_l)
pressRrelease_char(Key.cmd) elif (ge == "Key.alt_r"):
elif (ge == "Key.caps_lock"): pressRrelease_char(Key.alt_r)
pressRrelease_char(Key.caps_lock) elif (ge == "Key.cmd"):
elif (ge == "Key.tab"): pressRrelease_char(Key.cmd)
pressRrelease_char(Key.tab) elif (ge == "Key.caps_lock"):
elif (ge == "Key.f1"): pressRrelease_char(Key.caps_lock)
pressRrelease_char(Key.f1) elif (ge == "Key.tab"):
elif (ge == "Key.f2"): pressRrelease_char(Key.tab)
pressRrelease_char(Key.f2) elif (ge == "Key.f1"):
elif (ge == "Key.f3"): pressRrelease_char(Key.f1)
pressRrelease_char(Key.f3) elif (ge == "Key.f2"):
elif (ge == "Key.f4"): pressRrelease_char(Key.f2)
pressRrelease_char(Key.f4) elif (ge == "Key.f3"):
elif (ge == "Key.f5"): pressRrelease_char(Key.f3)
pressRrelease_char(Key.f5) elif (ge == "Key.f4"):
elif (ge == "Key.f6"): pressRrelease_char(Key.f4)
pressRrelease_char(Key.f6) elif (ge == "Key.f5"):
elif (ge == "Key.f7"): pressRrelease_char(Key.f5)
pressRrelease_char(Key.f7) elif (ge == "Key.f6"):
elif (ge == "Key.f8"): pressRrelease_char(Key.f6)
pressRrelease_char(Key.f8) elif (ge == "Key.f7"):
elif (ge == "Key.f9"): pressRrelease_char(Key.f7)
pressRrelease_char(Key.f9) elif (ge == "Key.f8"):
elif (ge == "Key.f10"): pressRrelease_char(Key.f8)
pressRrelease_char(Key.f10) elif (ge == "Key.f9"):
elif (ge == "Key.f11"): pressRrelease_char(Key.f9)
pressRrelease_char(Key.f11) elif (ge == "Key.f10"):
elif (ge == "Key.f12"): pressRrelease_char(Key.f10)
pressRrelease_char(Key.f12) elif (ge == "Key.f11"):
elif (ge == "Key.esc"): pressRrelease_char(Key.f11)
pressRrelease_char(Key.esc) elif (ge == "Key.f12"):
elif (ge == "Key.insert"): pressRrelease_char(Key.f12)
pressRrelease_char(Key.insert) elif (ge == "Key.esc"):
elif (ge == "Key.delete"): pressRrelease_char(Key.esc)
pressRrelease_char(Key.delete) elif (ge == "Key.insert"):
elif (ge == "Key.end"): pressRrelease_char(Key.insert)
pressRrelease_char(Key.end) elif (ge == "Key.delete"):
elif (ge == "Key.num_lock"): pressRrelease_char(Key.delete)
pressRrelease_char(Key.num_lock) elif (ge == "Key.end"):
elif (ge == "Key.home"): pressRrelease_char(Key.end)
pressRrelease_char(Key.home) elif (ge == "Key.num_lock"):
elif (ge == "Key.page_up"): pressRrelease_char(Key.num_lock)
pressRrelease_char(Key.page_up) elif (ge == "Key.home"):
elif (ge == "Key.page_down"): pressRrelease_char(Key.home)
pressRrelease_char(Key.page_down) elif (ge == "Key.page_up"):
elif (ge == "Key.pause"): pressRrelease_char(Key.page_up)
pressRrelease_char(Key.pause) elif (ge == "Key.page_down"):
elif (ge == "Key.scroll_lock"): pressRrelease_char(Key.page_down)
pressRrelease_char(Key.scroll_lock) elif (ge == "Key.pause"):
elif (ge == "Key.menu"): pressRrelease_char(Key.pause)
pressRrelease_char(Key.menu) elif (ge == "Key.scroll_lock"):
elif (ge == "Key.print_screen"): pressRrelease_char(Key.scroll_lock)
pressRrelease_char(Key.print_screen) elif (ge == "Key.menu"):
elif (ge == "Key.left"): pressRrelease_char(Key.menu)
pressRrelease_char(Key.left) elif (ge == "Key.print_screen"):
elif (ge == "Key.up"): pressRrelease_char(Key.print_screen)
pressRrelease_char(Key.up) elif (ge == "Key.left"):
elif (ge == "Key.right"): pressRrelease_char(Key.left)
pressRrelease_char(Key.right) elif (ge == "Key.up"):
elif (ge == "Key.down"): pressRrelease_char(Key.up)
pressRrelease_char(Key.down) elif (ge == "Key.right"):
else: pressRrelease_char(Key.right)
pressRrelease_char((ge)) elif (ge == "Key.down"):
except: pressRrelease_char(Key.down)
print("an error occured with ", ge) else:
g.close() pressRrelease_char((ge))
except:
print("an error occured with ", ge)
g.close()

View File

@ -1,6 +1,5 @@
import socket import socket
import os import os
import tqdm
import pynput import pynput
from pynput.mouse import Button, Controller from pynput.mouse import Button, Controller
import time import time
@ -38,57 +37,53 @@ filename = os.path.basename(filename)
filesize = int(filesize) filesize = int(filesize)
# start receiving the file from the socket # start receiving the file from the socket
# and writing to the file stream # and writing to the file stream
progress = tqdm.tqdm(range(filesize), f"Receiving {filename}", unit="B", unit_scale=True, unit_divisor=1024)
#with open(filename, "wb") as f: #with open(filename, "wb") as f:
while True: while True:
for _ in progress: # read 1024 bytes from the socket (receive)
# read 1024 bytes from the socket (receive) bytes_read = client_socket.recv(BUFFER_SIZE)
bytes_read = client_socket.recv(BUFFER_SIZE) if not bytes_read:
if not bytes_read: # nothing is received
# nothing is received # file transmitting is done take another time
# file transmitting is done take another time break
break # write to the file the bytes we just received
# write to the file the bytes we just received
# update the progress bar # update the progress bar
f = open(filename, 'wb') f = open(filename, 'wb')
f.write(bytes_read) f.write(bytes_read)
# update the progress bar f.close()
progress.update(len(bytes_read))
f.close()
g = open(filename, 'r') g = open(filename, 'r')
ge = g.read() ge = g.read()
print (ge) print (ge)
TrR = ge[0:1] TrR = ge[0:1]
ge = ge[1:] ge = ge[1:]
try: try:
y = int(ge[((int(ge.find(',')+1))):]) y = int(ge[((int(ge.find(',')+1))):])
x = int(ge[:(int(ge.find(',')))]) x = int(ge[:(int(ge.find(',')))])
print(x) print(x)
print(y) print(y)
mouse.position = (x,y) mouse.position = (x,y)
if (TrR == 'R'): if (TrR == 'R'):
mouse.click(Button.right, 1) mouse.click(Button.right, 1)
print (TrR) print (TrR)
else: else:
mouse.click(Button.left, 1) mouse.click(Button.left, 1)
print (TrR) print (TrR)
except: except:
print ("error") print ("error")
g.close() g.close()

View File

@ -1,6 +1,5 @@
import socket import socket
import os import os
import tqdm
from tkinter import * from tkinter import *
from pynput import keyboard from pynput import keyboard
@ -46,9 +45,8 @@ s.send(f"{filename}{SEPARATOR}{filesize}".encode())
def sendfile(): def sendfile():
# start sending the file # start sending the file
progress = tqdm.tqdm(range(filesize), f"Sending {filename}", unit="B", unit_scale=True, unit_divisor=1024)
with open(filename, "rb") as f: with open(filename, "rb") as f:
for _ in progress: while True:
# read the bytes from the file # read the bytes from the file
bytes_read = f.read(BUFFER_SIZE) bytes_read = f.read(BUFFER_SIZE)
if not bytes_read: if not bytes_read:
@ -57,8 +55,6 @@ def sendfile():
# we use sendall to assure transimission in # we use sendall to assure transimission in
# busy networks # busy networks
s.sendall(bytes_read) s.sendall(bytes_read)
# update the progress bar
progress.update(len(bytes_read))
# close the socket # close the socket
#s.close() #s.close()

View File

@ -1,6 +1,5 @@
import socket import socket
import os import os
import tqdm
from tkinter import * from tkinter import *
from pynput import keyboard from pynput import keyboard
@ -45,9 +44,8 @@ s.send(f"{filename}{SEPARATOR}{filesize}".encode())
def sendfile(): def sendfile():
# start sending the file # start sending the file
progress = tqdm.tqdm(range(filesize), f"Sending {filename}", unit="B", unit_scale=True, unit_divisor=1024)
with open(filename, "rb") as f: with open(filename, "rb") as f:
for _ in progress: while True:
# read the bytes from the file # read the bytes from the file
bytes_read = f.read(BUFFER_SIZE) bytes_read = f.read(BUFFER_SIZE)
if not bytes_read: if not bytes_read:
@ -56,8 +54,6 @@ def sendfile():
# we use sendall to assure transimission in # we use sendall to assure transimission in
# busy networks # busy networks
s.sendall(bytes_read) s.sendall(bytes_read)
# update the progress bar
progress.update(len(bytes_read))
# close the socket # close the socket
#s.close() #s.close()

View File

@ -1,6 +1,5 @@
import socket import socket
import os import os
import tqdm
from pynput import keyboard from pynput import keyboard
from pynput.mouse import Button, Controller from pynput.mouse import Button, Controller
from pynput import mouse from pynput import mouse
@ -33,9 +32,8 @@ s.send(f"{filename}{SEPARATOR}{filesize}".encode())
def sendfile(): def sendfile():
# start sending the file # start sending the file
progress = tqdm.tqdm(range(filesize), f"Sending {filename}", unit="B", unit_scale=True, unit_divisor=1024)
with open(filename, "rb") as f: with open(filename, "rb") as f:
for _ in progress: while True:
# read the bytes from the file # read the bytes from the file
bytes_read = f.read(BUFFER_SIZE) bytes_read = f.read(BUFFER_SIZE)
if not bytes_read: if not bytes_read:
@ -44,8 +42,6 @@ def sendfile():
# we use sendall to assure transimission in # we use sendall to assure transimission in
# busy networks # busy networks
s.sendall(bytes_read) s.sendall(bytes_read)
# update the progress bar
progress.update(len(bytes_read))
# close the socket # close the socket
#s.close() #s.close()

View File

@ -1,16 +1,15 @@
import socket import socket
import os import os
import tqdm
from pynput import keyboard from pynput import keyboard
SEPARATOR = "<SEPARATOR>" SEPARATOR = "<SEPARATOR>"
BUFFER_SIZE = 4096 # send 4096 bytes each time step BUFFER_SIZE = 128 # send 4096 bytes each time step
# the ip address or hostname of the server, the receiver # the ip address or hostname of the server, the receiver
host = "10.4.27.243" host = "127.0.0.1"
# the port, let's use 5001 # the port, let's use 5001
port = 5001 port = 5001
# the name of file we want to send, make sure it exists # the name of file we want to send, make sure it exists
@ -30,9 +29,8 @@ s.send(f"{filename}{SEPARATOR}{filesize}".encode())
def sendfile(): def sendfile():
# start sending the file # start sending the file
progress = tqdm.tqdm(range(filesize), f"Sending {filename}", unit="B", unit_scale=True, unit_divisor=1024)
with open(filename, "rb") as f: with open(filename, "rb") as f:
for _ in progress: while True:
# read the bytes from the file # read the bytes from the file
bytes_read = f.read(BUFFER_SIZE) bytes_read = f.read(BUFFER_SIZE)
if not bytes_read: if not bytes_read:
@ -41,8 +39,6 @@ def sendfile():
# we use sendall to assure transimission in # we use sendall to assure transimission in
# busy networks # busy networks
s.sendall(bytes_read) s.sendall(bytes_read)
# update the progress bar
progress.update(len(bytes_read))
# close the socket # close the socket
#s.close() #s.close()