2

For some reason I get wrong mousepointer positions with pynput.

The 0,0 position is right and the 1920x1080 position is right but in between there is an error of around 100px.

from pynput.mouse import Listener


def on_click(x, y, button, pressed):
    if pressed:
        print("Mouse clicked at ({0}, {1}) with {2}".format(x, y, button))


with Listener(on_click=on_click) as listener:
    listener.join()
nanobot
  • 108
  • 5
  • 18
  • You're code seems to be running fine for me. How do you know that there is an error? – funie200 Jun 14 '19 at 11:56
  • 1
    I found out what was wrong. I had my scaling in windows at 125% (this makes eveything 25% bigger). This kinda produced the wrong position values in pynput. As I set the scaling back to 100% everything worked fine. – nanobot Jun 15 '19 at 12:16

1 Answers1

1

I had the same problem, and I didn't know anything to do- so I just timed all positional values by 1.25, which gave me the dimensions: 1918, 1078. you could use 1.25081433225 to get the exact dimension if you wish.

from pynput.mouse import Listener

def on_click(x, y, button, pressed):
    if pressed:
        print("Mouse clicked at ({0}, {1}) with {2}".format(x*1.25,y*1.25,button))


with Listener(on_click=on_click) as listener:
    listener.join()
kk.
  • 3,747
  • 12
  • 36
  • 67
  • 1
    You probably had the same issue as me. The scaling displays scaling in windows caused the values to be off. My display scaling was at 125%, so it was 1.25 off. – nanobot Sep 17 '21 at 19:44