-
Notifications
You must be signed in to change notification settings - Fork 1
/
Controller.py
executable file
·47 lines (30 loc) · 1017 Bytes
/
Controller.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import json
from LockMonitor import ComputerMonitor
from KeyboardListener import KeyboardListener
from TcpServer import TcpServer
from service import *
def on_message_received(data):
command_message = json.loads(data)
script = command_message["script"]
params = command_message["params"]
exec(script)
def on_screen_locked():
print("screen locked")
data = json.dumps({"command": 2, "message": ""})
print(data)
tcpServer.send_text(data)
computerMonitor = ComputerMonitor(on_screen_locked)
def on_tcp_connected():
if not computerMonitor.started:
computerMonitor.start()
tcpServer = TcpServer()
tcpServer.set_receive_listener(on_message_received)
tcpServer.connected_listener = on_tcp_connected
tcpServer.start()
keyboardListener = KeyboardListener(tcpServer)
def onTrans():
print("need trans")
content = getClipContent()
text = json.dumps({"command": 1, "message": content})
tcpServer.send_text(text)
keyboardListener.listen_keyboard(onTrans)