main.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!/usr/bin/env python
  2. # -*- encoding: utf-8 -*-
  3. '''
  4. @Contact : liuyuqi.gov@msn.cn
  5. @Time : 2022/10/05 06:31:20
  6. @License : Copyright © 2017-2022 liuyuqi. All Rights Reserved.
  7. @Desc : 程序入口
  8. '''
  9. import threading
  10. from cyber.tcp_server import TcpServer
  11. from cyber.keyboard_listener import KeyboardListener
  12. from cyber.service import *
  13. from cyber.computer_monitor import ComputerMonitor
  14. from cyber.command_message import CommandMessage;
  15. import json
  16. import pyautogui
  17. from cyber.keyboard_manager import *
  18. import time
  19. def on_message_received(data):
  20. '''
  21. 回调函数, exec执行命令
  22. '''
  23. command_message = json.loads(data)
  24. script = command_message["script"]
  25. params = command_message["params"]
  26. exec(script)
  27. def on_screen_locked():
  28. '''
  29. 回调函数
  30. '''
  31. print("screen locked")
  32. data = json.dumps({"command":2,"message":""})
  33. print(data)
  34. tcpServer.send_text(data)
  35. computerMonitor = ComputerMonitor(on_screen_locked)
  36. def on_tcp_connected():
  37. '''
  38. 回调函数
  39. '''
  40. if not computerMonitor.started:
  41. computerMonitor.start()
  42. def onTrans():
  43. '''
  44. 回调函数
  45. '''
  46. print("need trans")
  47. content = getClipContent()
  48. text = json.dumps({"command":1,"message":content})
  49. tcpServer.send_text(text)
  50. if __name__=='__main__':
  51. tcpServer = TcpServer()
  52. tcpServer.set_receive_listener(on_message_received)
  53. tcpServer.connected_listener = on_tcp_connected
  54. tcpServer.start()
  55. # 按键监听
  56. keyboardListener = KeyboardListener(tcpServer)
  57. keyboardListener.listen_keyboard(onTrans)