The API for modeling mouse events depends on your platform. I do not know a cross-platform solution.
On Windows, you can access the Win32 API thanks to ctypes. see mouse_event on MSDN . You May Also Want Pywinauto
. . GetCursorPos MSDN. , API , . , PIL . , PIL Windows paltform, .
:
def grab_main_color(self, rect, max_colors=256):
"""returns a tuple with the RGB value of the most present color in the given rect"""
img=ImageGrab.grab(rect)
colors = img.getcolors(max_colors)
max_occurence, most_present = 0, 0
try:
for c in colors:
if c[0] > max_occurence:
(max_occurence, most_present) = c
return most_present
except TypeError:
raise Exception("Too many colors in the given rect")