hel 1 年間 前
コミット
33964efe64
4 ファイル変更139 行追加6 行削除
  1. 10 0
      drission/demo.py
  2. 0 1
      listenTest.py
  3. 112 0
      monitorPyWin32.py
  4. 17 5
      monitorTest.py

+ 10 - 0
drission/demo.py

@@ -0,0 +1,10 @@
+from DrissionPage import ChromiumPage
+
+page = ChromiumPage()
+page.get('http://g1879.gitee.io/DrissionPageDocs')
+# chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/notification.html
+# chrome-extension://ppbibelpcjmhbdihakflkdcoccbgbkpo/notification.html
+# chrome-extension://mcohilncbfahbmgdjkbpemcciiolgcge/notification.html
+# init set path
+# from DrissionPage.easy_set import set_paths
+# set_paths(chrome_path=r'C:\Program Files\Google\Chrome\Application\chrome.exe',)

+ 0 - 1
listenTest.py

@@ -1,5 +1,4 @@
 import asyncio
-import time
 
 import pika
 from pynput import mouse

+ 112 - 0
monitorPyWin32.py

@@ -0,0 +1,112 @@
+#!/usr/bin/env python
+import json
+import os
+import signal
+import sys
+import time
+
+import pika
+import win32api
+import win32con
+
+import screen
+
+screenNumber = screen.arrange_slave()
+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')}")
+    print(time.time())
+
+    # 执行其他操作,例如记录日志、更新数据库等
+    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, auto_delete=True)
+
+    # 绑定队列到交换机
+    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()
+
+
+def signal_handler(sig, frame):
+    print("Caught signal, closing connection and channel")
+    channel.close()
+    connection.close()
+    sys.exit(0)
+
+
+def handleMessage(properties, body):
+    print('handle')
+    jsonObject = json.loads(body)
+    if jsonObject['function'] == 0:
+        on_click(jsonObject['x'], jsonObject['y'], jsonObject['button'])
+    else:
+        on_scroll(jsonObject['x'], jsonObject['y'], jsonObject['dx'], jsonObject['dy'])
+
+
+def on_click(x, y, button):
+    counter = 0
+    for i in range(0, screenNumber):
+        win32api.SetCursorPos((x + i * 500, y))
+        # time.sleep(0.05)
+        if 'left' in button:
+            win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
+            win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
+            # mouseController.click(Button.left, 1)
+            counter = counter + 1
+            print(counter)
+        else:
+            win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0)
+            win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0)
+            counter = counter + 1
+            print(counter)
+
+
+def on_scroll(x, y, dx, dy):
+    counter = 0
+
+    for i in range(0, screenNumber):
+        win32api.SetCursorPos((x + i * 500, y))
+        win32api.mouse_event(win32con.MOUSEEVENTF_WHEEL, 0, 0, dy)
+        print(counter)
+
+
+signal.signal(signal.SIGINT, signal_handler)
+signal.signal(signal.SIGTERM, signal_handler)
+if __name__ == '__main__':
+    try:
+        main()
+    except KeyboardInterrupt:
+        print('Interrupted')
+        try:
+            channel.close()
+            connection.close()
+            sys.exit(0)
+
+        except SystemExit:
+            channel.close()
+            connection.close()
+            os._exit(0)
+    finally:
+        channel.close()
+        connection.close()

+ 17 - 5
monitorTest.py

@@ -34,7 +34,7 @@ def main():
 
     # 定义一个队列
     queue_name = 'hello'
-    channel.queue_declare(queue=queue_name)
+    channel.queue_declare(queue=queue_name, auto_delete=True)
 
     # 绑定队列到交换机
     routing_key = ''
@@ -56,6 +56,7 @@ def signal_handler(sig, frame):
 
 
 def handleMessage(properties, body):
+    print('handle')
     jsonObject = json.loads(body)
     if jsonObject['function'] == 0:
         on_click(jsonObject['x'], jsonObject['y'], jsonObject['button'])
@@ -64,18 +65,29 @@ def handleMessage(properties, body):
 
 
 def on_click(x, y, button):
+    counter = 0
     for i in range(0, screenNumber):
-        mouseController.position = (x + i * 800, y)
+        mouseController.position = (x + i * 500, y)
+        # time.sleep(0.05)
         if 'left' in button:
-            mouseController.click(Button.left, 1)
+            mouseController.press(Button.left)
+            time.sleep(0.1)
+            mouseController.release(Button.left)
+            # mouseController.click(Button.left, 1)
+            counter = counter + 1
+            print(counter)
         else:
             mouseController.click(Button.right, 1)
-
+            counter = counter + 1
+            print(counter)
 
 def on_scroll(x, y, dx, dy):
+    counter = 0
+
     for i in range(0, screenNumber):
-        mouseController.position = (x +i * 800, y)
+        mouseController.position = (x + i * 500, y)
         mouseController.scroll(dx, dy)
+        print(counter)
 
 
 signal.signal(signal.SIGINT, signal_handler)