xxxxxxxxxx
# pip install pynput
from pynput import mouse
def on_click(x, y, button, pressed):
if pressed:
print("mouse button press")
with mouse.Listener(on_click=on_click) as listener:
listener.join()
image.mefiz.com
xxxxxxxxxx
import mouse
mouse.is_pressed("left")
#Gives you a boolean whether the left mouse button is pressed.
#You can also do the same with the right button using:
mouse.is_pressed("right")
#learn more at https://www.thepythoncode.com/article/control-mouse-python
xxxxxxxxxx
# Code to check if left or right mouse buttons were pressed
import win32api
import time
state_left = win32api.GetKeyState(0x01) # Left button down = 0 or 1. Button up = -127 or -128
state_right = win32api.GetKeyState(0x02) # Right button down = 0 or 1. Button up = -127 or -128
while True:
a = win32api.GetKeyState(0x01)
b = win32api.GetKeyState(0x02)
if a != state_left: # Button state changed
state_left = a
print(a)
if a < 0:
print('Left Button Pressed')
else:
print('Left Button Released')
if b != state_right: # Button state changed
state_right = b
print(b)
if b < 0:
print('Right Button Pressed')
else:
print('Right Button Released')
time.sleep(0.001)