一个可以为我玩Flash游戏的Python程序
是的,这正是我想要实现的,不用问为什么:) 因为这主要和操作系统有关,我会使用Windows或Linux(哪个简单用哪个)。 我的程序每秒会: 1. 截个屏,分析一下屏幕上的内容(这个我会做) 2. 然后把鼠标移动到某个位置,点击一下 就这些。 我最关心的是:有没有什么库可以用来截屏,然后在屏幕上某个地方点击一下?
3 个回答
1
你可以试试用Selenium RC加上Python的Selenium驱动。这样可以让你在浏览器里截屏,还有一个叫ClickAt的方法,可以通过输入坐标来点击页面上的某个地方。
2
使用ctypes和user32的调用。这是第二部分:
from ctypes import *
windll.user32.SetCursorPos(x, y)
SendInput就是你需要的东西,用来模拟鼠标点击,这里有你点击所需的具体内容:http://kvance.livejournal.com/985732.html
点击的代码如下(我试过,效果很好):
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]))
3
我之前也做过这个事情——用PIL来获取屏幕截图,然后用pywinauto来模拟鼠标点击。