I want to use mouse listener in Pynput Module to monitor the click event. Ant according to the event status, it will trigger one function. But it seems something wrong with the event status.
from pynput.keyboard import Controller, Key, Listener
from pynput import mouse
from pynput import keyboard
import pythoncom
from ctypes import *
flag = False
def on_right_click(x, y, button, pressed):
global flag
# boolFlag = False
button_name = ''
if button == mouse.Button.right:
user32 = windll.LoadLibrary('user32.dll')
if flag == True:
user32.BlockInput(False)
flag = False
else:
user32.BlockInput(True)
flag = True
print(flag)
button_name = 'Right Button'
elif button == mouse.Button.left:
button_name = 'Left Button'
if pressed:
print('{0} is pressed at {1}, {2}'.format(button_name, x, y))
if not pressed:
return False
while True:
with mouse.Listener(on_click=on_right_click) as listener:
listener.join()
Normally, Flag will change once and it will trigger the BlockInput function, but below is the real results:
True
Right Button is pressed at 3478, 303
False
So, why the flag is changed twice?