Try this solution:
from pynput import mouse
def on_click(x, y, button, pressed):
print(x,y)
with mouse.Listener(on_click=on_click) as listener:
listener.join()
The result of above code is:
830 345 Button.left True
830 345 Button.left False
The values of above code will print twice i.e one for co-ordinate value for button pressed and one co-ordinate value for button released.
So to get both the co-ordinates of mouse click event and released event use the above code.
So to print the value of co-ordinates where mouse button is clicked use the below code:
from pynput import mouse
def on_click(x, y, button, pressed):
if pressed == True:
print(x,y)
with mouse.Listener(on_click=on_click) as listener:
listener.join()
AND
So to print the value of co-ordinates where mouse button is released use the below code:
from pynput import mouse
def on_click(x, y, button, pressed):
if pressed == False:
print(x,y)
with mouse.Listener(on_click=on_click) as listener:
listener.join()