python program that plays flash games for me

女生的网名这么多〃 提交于 2019-12-06 15:41:11

I've done this very thing before - use PIL to get the screenshots, and pywinauto to generate the mouse clicks.

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]))

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!