My Def for clicking and controlling the mouse in windows mac and linux
If you are in windows you'll need to install pywin32 and if you are in linux or OSX then you'll need to install xdotool
def click(x, y):
if os.name == "posix":
os.system("xdotool mousemove " + str(x) + " " + str(y))
os.system("xdotool click 1")
else:
win32api.SetCursorPos((x,y))
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,x,y,0,0)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,x,y,0,0)
in the code it's basically saying if the operating system is posix (linux/mac) then run the nesseary terminal commands the move the mouse to x,y then click it. but if the operating system is not Linux or windows then use win32api (part of pywin32) to move the mouse then click it.
in windows you must:
in Linux/Mac you must:import win32api, win32con
import os
No comments:
Post a Comment