Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a mouse scroll event using python

I found this, Controlling mouse with Python, question really helpful in creating a script to move the mouse and click the mouse using Python. Is it possible to create a mouse scroll event also? Also, what about the forward and back button?

like image 491
Alexis Avatar asked Jun 17 '26 00:06

Alexis


1 Answers

Just for "late" viewers, this would require you to change the 4th argument dwData... I think it would look like this:

import win32api
from win32con import *

#Scroll one up
win32api.mouse_event(MOUSEEVENTF_WHEEL, x, y, 1, 0)

#Scroll one down
win32api.mouse_event(MOUSEEVENTF_WHEEL, x, y, -1, 0)

#Scroll one to the right
win32api.mouse_event(MOUSEEVENTF_HWHEEL, x, y, 1, 0)

#Scroll one to the left
win32api.mouse_event(MOUSEEVENTF_HWHEEL, x, y, -1, 0)


More information? The win-api docs are really good:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms646260%28v=vs.85%29.aspx
like image 169
JHolta Avatar answered Jun 19 '26 14:06

JHolta