Combining Mouse Event Monitoring and Listener Programs: Python Multi-threading Exploration

22 Views Asked by At

I hope that while running Listener.py, Monitor.py can also be executed simultaneously. I want to modify Monitor.py to create an array with a maximum size of 10. When the number of mouse signals received reaches 10, it should automatically terminate and print out the signals stored in the array. If the number of signals received is less than 10 but a mouse scroll is detected, it should terminate and output directly. I would like to know how can I combine Listener.py and Monitor.py since Listener.py can only be executed with python3 command, while Monitor.py can only be executed with python command.

Listner.py

from pynput.mouse import Listener

# Listen for mouse events
def on_click(x, y, button, pressed):
    # Do stuff here
    pass

with Listener(on_click=on_click, suppress=True) as listener:
    listener.join()
    enter code here

Monitor.py:

from pymouse import PyMouseEvent

def fibo():
    a = 0
    yield a
    b = 1
    yield b
    while True:
        a, b = b, a + b
        yield b

class Clickonacci(PyMouseEvent):
    def __init__(self):
        PyMouseEvent.__init__(self)
        self.fibo = fibo()

    def click(self, x, y, button, press):
        if press:
            if button == 1:
                print("left QAQp")
            elif button == 2:
                print("right owOb")
                

C = Clickonacci()
C.run()
0

There are 0 best solutions below