-
-
Save xiada/9e364ab4c9d946f5e10c to your computer and use it in GitHub Desktop.
Revisions
-
franzwong revised this gist
Oct 14, 2012 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -85,4 +85,4 @@ def clickButton(windowTitle, buttonText): print 'time interval : %s' % interval print timeIntervalCall(lambda : clickButton(windowTitle, buttonText), interval) -
franzwong revised this gist
Oct 14, 2012 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -54,7 +54,7 @@ def searchButton(windowTitle, buttonText): return buttonHwnd return None # interval - in terms of second def timeIntervalCall(fn, interval): import time while True: @@ -77,6 +77,7 @@ def clickButton(windowTitle, buttonText): windowTitle = sys.argv[1] buttonText = sys.argv[2] # interval - in term of second interval = int(sys.argv[3]) print 'title : %s' % windowTitle -
franzwong revised this gist
Oct 14, 2012 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -49,8 +49,8 @@ def clickButtonByHwnd(buttonHwnd): def searchButton(windowTitle, buttonText): exactMatch = True for hwnd in search(windowTitle, exactMatch): for buttonHwnd in search(buttonText, exactMatch, hwnd): return buttonHwnd return None -
franzwong revised this gist
Oct 14, 2012 . 1 changed file with 4 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -48,8 +48,9 @@ def clickButtonByHwnd(buttonHwnd): SendMessage(buttonHwnd, 0x00F5, 0, 0) # 0x00F5 - BM_CLICK def searchButton(windowTitle, buttonText): exactMatch = True for hwnd in search(windowTitle, exactMatch ): for buttonHwnd in search(buttonText, exactMatch , hwnd): return buttonHwnd return None @@ -83,4 +84,4 @@ def clickButton(windowTitle, buttonText): print 'time interval : %s' % interval print timeIntervalCall(lambda : clickButton(windowTitle, buttonText), interval) -
franzwong created this gist
Oct 14, 2012 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,86 @@ import sys import ctypes import time EnumWindows = ctypes.windll.user32.EnumWindows EnumChildWindows = ctypes.windll.user32.EnumChildWindows EnumWindowsProc = ctypes.WINFUNCTYPE(ctypes.c_bool, ctypes.POINTER(ctypes.c_int), ctypes.POINTER(ctypes.c_int)) GetWindowText = ctypes.windll.user32.GetWindowTextW GetWindowTextLength = ctypes.windll.user32.GetWindowTextLengthW IsWindowVisible = ctypes.windll.user32.IsWindowVisible SendMessage = ctypes.windll.user32.SendMessageW def getWindowText(hwnd): length = GetWindowTextLength(hwnd) buffer = ctypes.create_unicode_buffer(length + 1) GetWindowText(hwnd, buffer, length + 1) return buffer.value def match(title, text, exactMatch): match = False if exactMatch: if text == title: match = True else: if 0 < title.find(text): match = True return match def search(text, exactMatch, parentHwnd=None): resultHwnd = [] def enumProc(hwnd, lParam, text=text, exactMatch=exactMatch, resultHwnd=resultHwnd): title = getWindowText(hwnd) if match(title, text, exactMatch): resultHwnd.append(hwnd) return False return True if None == parentHwnd: EnumWindows(EnumWindowsProc(enumProc), 0) return resultHwnd else: EnumChildWindows(parentHwnd, EnumWindowsProc(enumProc), 0) return resultHwnd def clickButtonByHwnd(buttonHwnd): SendMessage(buttonHwnd, 0x00F5, 0, 0) # 0x00F5 - BM_CLICK def searchButton(windowTitle, buttonText): for hwnd in search(windowTitle, True): for buttonHwnd in search(buttonText, True, hwnd): return buttonHwnd return None # interval - in term of second def timeIntervalCall(fn, interval): import time while True: fn() time.sleep(interval) def clickButton(windowTitle, buttonText): print 'attempt to find button...' buttonHwnd = searchButton(windowTitle, buttonText) if None != buttonHwnd: print 'found' clickButtonByHwnd(buttonHwnd) else: print 'not found' if __name__ == '__main__': if 4 > len(sys.argv): print 'not enough parameter' sys.exit() windowTitle = sys.argv[1] buttonText = sys.argv[2] interval = int(sys.argv[3]) print 'title : %s' % windowTitle print 'button text : %s' % buttonText print 'time interval : %s' % interval print timeIntervalCall(lambda : clickButton(windowTitle, buttonText), interval)