Tuesday, May 10, 2016

How to control the Mouse in Python




You mayby know some of the anoying pseudo viruses wich launches a ghost - mouse on your pc. So how we can do that under Windows with python.

First you need to install the pywin32 package. You can do this of course easely with pip

pip install pywin32

Import:
import win32api, win32con

Mouve mouse:


win32api.SetCursorPos((x,y))

Click Left:


win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,x,y,0,0)

Click Right:


win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,x,y,0,0)

No comments:

Post a Comment