-2

I'm creating a program that utilizes the win32api mouse_event to move the mouse cursor to a certain position. However, the program is not working as expected. Any help would be most appreciated.

NOTE: I must use win32api and no other library.

Take this program for example:

import win32api

x = 1000
y = 1000
win32api.mouse_event(0x0001, int(x), int(y))

It should move the mouse cursor to the 1000th x and y pixels on the screen but it doesn't.

petezurich
  • 9,280
  • 9
  • 43
  • 57

1 Answers1

0

If you want to use SendInput, you need to use the ctypes library, and if you use the old mouse_event, you can use the following example.

import win32api 
import win32con
def click(x,y):
    cx_screen = win32api.GetSystemMetrics(win32con.SM_CXSCREEN)
    cy_screen = win32api.GetSystemMetrics(win32con.SM_CYSCREEN) 
    win32api.mouse_event(win32con.MOUSEEVENTF_MOVE | win32con.MOUSEEVENTF_ABSOLUTE, int(65535.0*x/cx_screen), int(65535.0*y/cy_screen))
click(1000,100)

How to Use SendInput to realize Mouse Click?

Strive Sun
  • 5,988
  • 1
  • 9
  • 26