def foreach_child(hwnd, lparam): # List of buttons labels to click. buttons = [ "yes", "oui", "ok", "accept", "accepter", "next", "suivant", "install", "installer", "run", "agree", "j'accepte", "enable", "activer", "don't send", "ne pas envoyer", "don't save", "continue", "continuer", "unzip", "dezip", "open", "ouvrir", "close the program", "later", "finish", "end", "allow", "allow access", "execute", "executer", "launch", "lancer", "save", "sauvegarder" ] # List of buttons labels to not click. dontclick = [ "don't run", "do not open", "block", ] classname = create_unicode_buffer(50) USER32.GetClassNameW(hwnd, classname, 50) # Check if the class of the child is button. if "button" in classname.value.lower(): # Get the text of the button. length = USER32.SendMessageW(hwnd, WM_GETTEXTLENGTH, 0, 0) text = create_unicode_buffer(length + 1) USER32.SetActiveWindow(hwnd) USER32.SetForegroundWindow(hwnd) USER32.SendMessageW(hwnd, WM_GETTEXT, length + 1, text) #log.info(text.value) USER32.SetActiveWindow(hwnd) USER32.SetForegroundWindow(hwnd) # Check if the button is set as "clickable" and click it. textval = text.value.replace("&", "").lower() for button in buttons: if button in textval: for btn in dontclick: if btn in textval: break else: log.info("Found button \"%s\", clicking it" % text.value) USER32.SetForegroundWindow(hwnd) KERNEL32.Sleep(1000) USER32.SendMessageW(hwnd, BM_CLICK, 0, 0) # Recursively search for childs (USER32.EnumChildWindows). return True
def foreach_window(hwnd, lparam): # If the window is visible, enumerate its child objects, looking # for buttons. if USER32.IsWindowVisible(hwnd): classname = create_unicode_buffer(50) USER32.GetClassNameW(hwnd, classname, 50) # If the window is one of the known class types that are inaccessible by User32, send Enter # This may proceed if there is a default action for win in default_action_win: if win in classname.value.lower(): log.info( "Found inaccessible window of class %s. Sending Enter" % classname.value.lower()) USER32.SetActiveWindow(hwnd) USER32.SetForegroundWindow(hwnd) type_keyboard(0x09, 0x8F) type_keyboard(0x0D, 0x9C) USER32.EnumChildWindows(hwnd, EnumChildProc(foreach_child), 0) #Turning off the ability of pressing objects in PDF, URL is good enough #try: #Get PID of current window # win_pid = c_ulong(0) # USER32.GetWindowThreadProcessId(hwnd,byref(win_pid)) #Get application name from PID # procname = psutil.Process(win_pid.value) # applicname = procname.name() # tabVal = get_tab_val(win_pid.value) #If this is PDF # if "AcroRd" in applicname: # log.info("App Name %s",applicname) # log.info("TabValue: %s",str(tabVal)) # USER32.SetActiveWindow(hwnd) # USER32.SetForegroundWindow(hwnd) # log.info("Sending Tab and Enter") #We are sending Tab different number of times # to cover different URLs #for y in range(0,tabVal): # #Sending Tab # type_keyboard(0x09,0x0F) # time.sleep(0.1) #Sending Enter #type_keyboard(0x0D,0x1C) #time.sleep(10) #update_tab_val(win_pid.value) #except: # log.info("Raised exception") # e = sys.exc_info()[0] # log.info(str(e)) # e1 = sys.exc_info()[1] # log.info(str(e1)) return True