-
Notifications
You must be signed in to change notification settings - Fork 138
/
Controller.py
46 lines (35 loc) · 1.06 KB
/
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
import threading
from TcpServer import TcpServer
from KeyboardListener import KeyboardListener
from service import *
from ComputerMonitor import ComputerMonitor
from CommandMessage import CommandMessage;
import json
import pyautogui
from KeyboardManager import *
import time
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)