-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.py
31 lines (25 loc) · 832 Bytes
/
client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from pynput import keyboard
from json import dumps
from socket import socket, AF_INET, SOCK_STREAM
from sys import argv
address = argv[1]
with socket(AF_INET, SOCK_STREAM) as sock:
def on_press(key):
data = dumps(
{"command": "press", "keycode": _get_keycode(key)}) + "\n"
sock.sendall(data.encode())
def on_release(key):
data = dumps(
{"command": "release", "keycode": _get_keycode(key)}) + "\n"
sock.sendall(data.encode())
def _get_keycode(key):
try:
return key.value.vk
except AttributeError:
return key.vk
sock.connect((address, 8000))
with keyboard.Listener(on_press=on_press, on_release=on_release) as listener:
try:
listener.join()
except Exception as e:
print(e)