hel 1 жил өмнө
parent
commit
9a006c8654
3 өөрчлөгдсөн 84 нэмэгдсэн , 12 устгасан
  1. 12 7
      listenTest.py
  2. 50 5
      monitorTest.py
  3. 22 0
      queueFunc.py

+ 12 - 7
listenTest.py

@@ -22,13 +22,20 @@ def in_monitorZone():
         return False
 
 
-def on_move(x, y):
-    return
-    # print('Pointer moved to {0}'.format(
-    #     (x, y)))
+def on_click(x, y, button, pressed):
 
+    # function:0
+    # x:
+    # y:
+    # button
+    # pressed
+    #
+    # function:1
+    # x,
+    # y,
+    # dx,
+    # dy,
 
-def on_click(x, y, button, pressed):
     print('{0} at {1}'.format(
         'Pressed' if pressed else 'Released',
         (x, y)))
@@ -62,14 +69,12 @@ def on_scroll(x, y, dx, dy):
 
 # Collect events until released
 with mouse.Listener(
-        on_move=on_move,
         on_click=on_click,
         on_scroll=on_scroll) as listener:
     listener.join()
 
 # ...or, in a non-blocking fashion:
 listener = mouse.Listener(
-    on_move=on_move,
     on_click=on_click,
     on_scroll=on_scroll)
 listener.start()

+ 50 - 5
monitorTest.py

@@ -1,8 +1,53 @@
-import time
+#!/usr/bin/env python
+import os
+import pika
+import sys
 
-from pynput import mouse
-from pynput.mouse import Controller, Button
-import asyncio
+import queueFunc
 
-import win32Test
+connection = pika.BlockingConnection(pika.ConnectionParameters(host='192.168.0.13', port=5672))
+channel = connection.channel()
 
+
+def callback(ch, method, properties, body):
+    # 处理消息的逻辑
+    print(f"Received message: {body.decode('utf-8')}")
+
+    # 执行其他操作,例如记录日志、更新数据库等
+    queueFunc.handleMessage(properties, body)
+    # 确认收到消息
+    ch.basic_ack(delivery_tag=method.delivery_tag)
+
+
+def main():
+    # 定义一个交换机(exchange)
+    exchange_name = 'sync'
+    channel.exchange_declare(exchange=exchange_name, exchange_type='fanout', durable=True)
+
+    # 定义一个队列
+    queue_name = 'hello'
+    channel.queue_declare(queue=queue_name)
+
+    # 绑定队列到交换机
+    routing_key = ''
+    channel.queue_bind(exchange=exchange_name, queue=queue_name, routing_key=routing_key)
+
+    print(f'Queue {queue_name} is now bound to exchange {exchange_name} with routing key {routing_key}')
+
+    channel.basic_qos(prefetch_count=1)
+
+    channel.basic_consume(queue=queue_name, on_message_callback=callback, auto_ack=True)
+    channel.start_consuming()
+
+
+if __name__ == '__main__':
+    try:
+        main()
+    except KeyboardInterrupt:
+        print('Interrupted')
+        try:
+            channel.close()
+            connection.close()
+            sys.exit(0)
+        except SystemExit:
+            os._exit(0)

+ 22 - 0
queueFunc.py

@@ -0,0 +1,22 @@
+from pynput.mouse import Controller, Button
+import json
+
+mouseController = Controller()
+
+
+def handleMessage(properties, body):
+    jsonObject = json.loads(body)
+    if jsonObject.function == 0:
+        on_click(jsonObject.x, jsonObject.y, jsonObject.button, jsonObject.pressed)
+    else:
+        on_scroll(jsonObject.x, jsonObject.y, jsonObject.dx, jsonObject.dy)
+    return
+
+
+def on_click(x, y, button, pressed):
+    mouseController.click(x, y, button, 1)
+
+
+def on_scroll(x, y, dx, dy):
+    mouseController.position = (x, y)
+    mouseController.scroll(dx, dy)