-
-
Save beckorz/8662202 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: cp932 -*- | |
import win32gui, win32ui, win32con | |
import time, random | |
import webbrowser | |
# IEでflashのペイントソフトを開く | |
ie = webbrowser.get(webbrowser.iexplore) | |
ie.open("http://www.ippei.org/flash/peint/flashpeint.html") | |
time.sleep(3) #ロード完了するまでちょっと待つ | |
def searchChildWindows(currentHwnd, wantedText="",wantedClass="", wantedFunction=""): | |
results = [] | |
childWindows = [] | |
try: | |
win32gui.EnumChildWindows(currentHwnd, | |
_windowEnumerationHandler, | |
childWindows) | |
except win32gui.error: | |
# This seems to mean that the control *cannot* have child windows, | |
# i.e. not a container. | |
return | |
#print "childWindows:", len(childWindows) | |
count = 0 | |
for childHwnd, windowText, windowClass in childWindows: | |
#print count | |
count = count + 1 | |
#descendentMatchingHwnds = searchChildWindows(childHwnd) | |
#if descendentMatchingHwnds: | |
# results += descendentMatchingHwnds | |
if wantedText and \ | |
not _normaliseText(wantedText) in _normaliseText(windowText): | |
continue | |
if wantedClass and \ | |
not windowClass == wantedClass: | |
continue | |
#if selectionFunction and \ | |
# not selectionFunction(childHwnd): | |
# continue | |
#print childHwnd, windowText, windowClass | |
results.append(childHwnd) | |
return results | |
def _windowEnumerationHandler(hwnd, resultList): | |
'''Pass to win32gui.EnumWindows() to generate list of window handle, | |
window text, window class tuples.''' | |
resultList.append((hwnd, | |
win32gui.GetWindowText(hwnd), | |
win32gui.GetClassName(hwnd))) | |
hwnd = win32gui.GetDesktopWindow() | |
hwnd2 = win32gui.FindWindowEx(hwnd, None, "IEFrame", None) | |
#タブウィンドウリストを取得 | |
results = searchChildWindows(hwnd2,wantedClass="TabWindowClass") | |
#FlashPlayerのウィンドウハンドルリストを保存する変数 | |
flashobjs = [] | |
#タブウィンドウ毎にFlashPlayerのウィンドウハンドルを取得 | |
for local_hwnd in results: | |
print local_hwnd, win32gui.GetClassName(local_hwnd), win32gui.GetWindowText(local_hwnd) | |
results2 = searchChildWindows(local_hwnd,wantedClass='MacromediaFlashPlayerActiveX') | |
print results2 | |
flashobjs.extend(results2) | |
## for DEBUG; ウィンドウハンドルの情報を表示 | |
for local_hwnd2 in results2: | |
print "\t", local_hwnd2, win32gui.GetClassName(local_hwnd2), win32gui.GetWindowText(local_hwnd2), win32gui.GetWindowRect(local_hwnd2) | |
# xy座標をlParamに変換 | |
def MAKELPARAM(point): | |
x, y = point | |
#lParam = (y << 16) | (x & 0xffff) | |
lParam = y << 16 | x | |
return lParam | |
# ウィンドウの座標(point) を 左クリックする | |
def send_click(local_hwnd, point): | |
#print local_hwnd | |
lParam = MAKELPARAM(point) | |
cwnd_paint = win32ui.CreateWindowFromHandle(local_hwnd) | |
#最初に LBUTTONUP がないとマウスクリック反応しなかった | |
cwnd_paint.SendMessage(win32con.WM_LBUTTONUP, 0, lParam) | |
cwnd_paint.SendMessage(win32con.WM_LBUTTONDOWN, win32con.MK_LBUTTON, lParam) | |
time.sleep(1) #1秒押しっぱなし | |
cwnd_paint.SendMessage(win32con.WM_LBUTTONUP, 0, lParam) | |
# 最初に見つけたFlashObject | |
# fixme: flashobjectを複数開いている場合にはまだ対応できてない。 | |
hwnd_flash = flashobjs[0] | |
#flashobject内の座標(30,315)(「ブラシ」ボタン)を左クリック | |
send_click(hwnd_flash, (26,130)) | |
#flashobject内のランダムな座標を左クリック x10回 | |
for n in range(10): | |
x = random.randint(50, 500) | |
y = random.randint(50, 500) | |
send_click(hwnd_flash, (x,y)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment