PDA

View Full Version : Set Mouse Position


javadi
11-13-2013, 01:36 PM
Dear all

In occasions, I need to set the position of the mouse to a certain location in the screen. I noticed that Vizard has some functions for getting mouse position. But I couldn't find anything for setting mouse position. I know that there are other libraries such as ctypes and win32api that you can use for setting the mouse position. I am wondering whether there is anything implemented in Vizard. Very many thanks.

Greetings :-)
Amir

Jeff
11-15-2013, 05:04 PM
Try the following:
import viz
import win32api
import win32con

viz.go()

x=0.1
y=0.9

win32api.mouse_event(win32con.MOUSEEVENTF_ABSOLUTE |win32con.MOUSEEVENTF_MOVE,int(65535*x),int(65535* (1.0-y)),0)

javadi
11-19-2013, 03:59 AM
Hi Jeff

Very many thanks for the code. What is the difference between your code and simply using the following code as you also use win32api?

win32api.SetCursorPos((int(x), int(y)))

This is a nice piece of code demonstrating it


import win32api
import time
import math

for i in range(100):
x = 500+math.sin(math.pi*i/100)*500
y = 500+math.cos(i)*100
win32api.SetCursorPos((int(x), int(y)))
time.sleep(.1)


Greetings
Amir