moses-palmer / pynput

Sends virtual input commands
GNU Lesser General Public License v3.0
1.79k stars 248 forks source link

Monitor position and move position are not the same point. #383

Closed utmcontent closed 3 years ago

utmcontent commented 3 years ago

Description A clear and concise description of what the bug is.

Use monitor to locate target point.

from pynput import mouse

def on_move(x, y):
    print('Pointer moved to {0}'.format(
        (x, y)))

def on_click(x, y, button, pressed):
    print('{0} at {1}'.format(
        'Pressed' if pressed else 'Released',
        (x, y)))
    if not pressed:
        # Stop listener
        return False

def on_scroll(x, y, dx, dy):
    print('Scrolled {0} at {1}'.format(
        'down' if dy < 0 else 'up',
        (x, y)))

# Collect events until released
with mouse.Listener(
        on_move=on_move,
        on_click=on_click,
        on_scroll=on_scroll) as listener:
    listener.join()

# ...or, in a non-blocking fashion:
listener = mouse.Listener(
    on_move=on_move,
    on_click=on_click,
    on_scroll=on_scroll)
listener.start()

When locate the example point 544,1422,use move function just move the wrong point.

from pynput.mouse import Button, Controller

mouse = Controller()
mouse.position=(0,0)
mouse.move(544,1422)

Platform and pynput version Your operating system and version, and the version of pynput. OS:win10 64bit,latest version pynput,python 3.8.8

I guess is the screen resolution problem.I have more than two display with two differenet resolution. Is there a way to solve tha problem?

Here is the gif to show the problem more clearlyl display_pynput

To Reproduce If possible, please include a short standalone code sample that reproduces the bug. Remember to surround it with code block markers to maintain indentation!

utmcontent commented 3 years ago
import ctypes
PROCESS_PER_MONITOR_DPI_AWARE=2
ctypes.windll.shcore.SetProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE)

Add three line of code can solve...

s-h-a-d-o-w commented 3 years ago

Thanks! Makes me wonder why that isn't the default.

Alright, since this is just a library, I suppose they wouldn't want to impose something like this on everything that uses it.