views:

65

answers:

2

Yes, that's what I need to achieve, don't ask why:) So, since this is mainly OS dependent stuff I will be using Windows or Linux (whatever is simpler) Every second my program will: 1. do a screenshot, analyze the board and other stuff (this I can do) 2. then move the mouse to some XY and do a left-click that's all My main concern is: is there any library for capturing screenshots and then left clicking somwhere on the screen?

A: 

You can try to use Selenium RC + python driver for Selenium. There are means of making browser screenshot, and there is ClickAt method which takes coordinates.

Kel
+1  A: 

Use ctypes and user32 calls. This is for the second part:

from ctypes import *
windll.user32.SetCursorPos(x, y)

SendInput is the thing that you're looking for to simulate mouse clicks, here's exactly what you need for clicking: http://kvance.livejournal.com/985732.html

The code for clicking is the following (tried it out, works great):

from ctypes import *
user32 = windll.user32

# START SENDINPUT TYPE DECLARATIONS
PUL = POINTER(c_ulong)
class KeyBdInput(Structure):
    _fields_ = [("wVk", c_ushort),
             ("wScan", c_ushort),
             ("dwFlags", c_ulong),
             ("time", c_ulong),
             ("dwExtraInfo", PUL)]

class HardwareInput(Structure):
    _fields_ = [("uMsg", c_ulong),
             ("wParamL", c_short),
             ("wParamH", c_ushort)]

class MouseInput(Structure):
    _fields_ = [("dx", c_long),
             ("dy", c_long),
             ("mouseData", c_ulong),
             ("dwFlags", c_ulong),
             ("time",c_ulong),
             ("dwExtraInfo", PUL)]

class Input_I(Union):
    _fields_ = [("ki", KeyBdInput),
              ("mi", MouseInput),
              ("hi", HardwareInput)]

class Input(Structure):
    _fields_ = [("type", c_ulong),
             ("ii", Input_I)]

class POINT(Structure):
    _fields_ = [("x", c_ulong),
             ("y", c_ulong)]
# END SENDINPUT TYPE DECLARATIONS

FInputs = Input * 2
extra = c_ulong(0)

click = Input_I()
click.mi = MouseInput(0, 0, 0, 2, 0, pointer(extra))
release = Input_I()
release.mi = MouseInput(0, 0, 0, 4, 0, pointer(extra))

x = FInputs( (0, click), (0, release) )
user32.SendInput(2, pointer(x), sizeof(x[0]))
Soulseekah
Also check this out: http://code.google.com/p/pywinauto/
Soulseekah
Also this: http://code.google.com/p/pymouse/
Soulseekah
Screenshots: http://www.pythonware.com/library/pil/handbook/imagegrab.htm
Soulseekah