def capture_text(): if os.name == 'nt': wnd = win32ui.GetForegroundWindow() print(wnd.GetWindowText()) return get_clipboard() else: print('Unsupported OS')
def start_presentation(self): """ Starts a presentation from the beginning. """ log.debug('start_presentation') # SlideShowWindow measures its size/position by points, not pixels # https://technet.microsoft.com/en-us/library/dn528846.aspx try: dpi = win32ui.GetActiveWindow().GetDC().GetDeviceCaps(88) except win32ui.error: try: dpi = win32ui.GetForegroundWindow().GetDC().GetDeviceCaps( 88) except win32ui.error: dpi = 96 size = ScreenList().current.display_geometry ppt_window = None try: # Disable the presentation console self.presentation.SlideShowSettings.ShowPresenterView = 0 # Start the presentation ppt_window = self.presentation.SlideShowSettings.Run() except (AttributeError, pywintypes.com_error): log.exception('Caught exception while in start_presentation') trace_error_handler(log) self.show_error_msg() if ppt_window and not Registry().get('settings').value( 'presentations/powerpoint control window'): try: ppt_window.Top = size.y() * 72 / dpi ppt_window.Height = size.height() * 72 / dpi ppt_window.Left = size.x() * 72 / dpi ppt_window.Width = size.width() * 72 / dpi except AttributeError: log.exception('AttributeError while in start_presentation') # Find the presentation window and save the handle for later self.presentation_hwnd = None if ppt_window: log.debug('main display size: y={y:d}, height={height:d}, ' 'x={x:d}, width={width:d}'.format( y=size.y(), height=size.height(), x=size.x(), width=size.width())) try: win32gui.EnumWindows(self._window_enum_callback, size) except pywintypes.error: # When _window_enum_callback returns False to stop the enumeration (looping over open windows) # it causes an exception that is ignored here pass # Make sure powerpoint doesn't steal focus, unless we're on a single screen setup if len(ScreenList()) > 1: Registry().get('main_window').activateWindow()
def start_presentation(self): """ Starts a presentation from the beginning. """ log.debug('start_presentation') # SlideShowWindow measures its size/position by points, not pixels # https://technet.microsoft.com/en-us/library/dn528846.aspx try: dpi = win32ui.GetActiveWindow().GetDC().GetDeviceCaps(88) except win32ui.error: try: dpi = win32ui.GetForegroundWindow().GetDC().GetDeviceCaps(88) except win32ui.error: dpi = 96 size = ScreenList().current['size'] ppt_window = None try: ppt_window = self.presentation.SlideShowSettings.Run() except (AttributeError, pywintypes.com_error) as e: log.exception('Caught exception while in start_presentation') log.exception(e) trace_error_handler(log) self.show_error_msg() if ppt_window and not Settings().value('presentations/powerpoint control window'): try: ppt_window.Top = size.y() * 72 / dpi ppt_window.Height = size.height() * 72 / dpi ppt_window.Left = size.x() * 72 / dpi ppt_window.Width = size.width() * 72 / dpi except AttributeError as e: log.exception('AttributeError while in start_presentation') log.exception(e) # Find the presentation window and save the handle for later self.presentation_hwnd = None if ppt_window: log.debug('main display size: y=%d, height=%d, x=%d, width=%d' % (size.y(), size.height(), size.x(), size.width())) win32gui.EnumWindows(self._window_enum_callback, size) # Make sure powerpoint doesn't steal focus, unless we're on a single screen setup if len(ScreenList().screen_list) > 1: Registry().get('main_window').activateWindow()
def doTyping(): the_text = open("text.txt").read().split("\n") text_index = 0 text_max = len(the_text) - 1 while True: if text_index > text_max: text_index = 0 window = win32ui.GetForegroundWindow() windowtext = window.GetWindowText() if not windowtext.__contains__(targetwindow): exit(0) print the_text[text_index] window_searcher.send_line(the_text[text_index]) text_index +=1 time.sleep(0.7)
def initialize(self, hndle=None): if self.dictObj != None: D("dictObj already initialized") return self.__class__.dictObj = natlink.DictObj() Cwnd = win32ui.GetForegroundWindow() for i in range(15000, 16000): try: ctrl = Cwnd.GetDlgItem(i) # edit box except: pass else: D("got ctrl: %s: %s"% (i, ctrl)) self.__class__.ctrl = ctrl break else: D("could not find a ctrl") self.__class__.ctrl = None self.dictObj.setBeginCallback(self.onTextBegin) self.dictObj.setChangeCallback(self.onTextChange) self.dictObj.activate(hndle)
def GUIAboutToInteract(self): "Called as the GUI is about to perform any interaction with the user" frame = win32ui.GetMainFrame() # Remember the enabled state of our main frame # may be disabled primarily if a modal dialog is displayed. # Only get at enabled via GetWindowLong. self.bFrameEnabled = frame.IsWindowEnabled() self.oldForeground = None fw = win32ui.GetForegroundWindow() if fw is not frame: self.oldForeground = fw # fw.EnableWindow(0) Leave enabled for now? self.oldFrameEnableState = frame.IsWindowEnabled() frame.EnableWindow(1) if self.inForcedGUI and not frame.IsWindowVisible(): frame.ShowWindow(win32con.SW_SHOW) frame.UpdateWindow() if self.curframe: SetInteractiveContext(self.curframe.f_globals, self.curframe.f_locals) else: SetInteractiveContext(None, None) self.GUIRespondDebuggerData()
"t": ord("T"), "u": ord("U"), "v": ord("V"), "w": ord("W"), "x": ord("X"), "y": ord("Y"), "z": ord("Z"), '0':0x30, '1':0x31, '2':0x32, '3':0x33, '4':0x34, '5':0x35, '6':0x36, '7':0x37, '8':0x38, '9':0x39, } def sendKey(button): win32api.keybd_event(keymap[button], 0, 0, 0) time.sleep(keyDelay) win32api.keybd_event(keymap[button], 0, win32con.KEYEVENTF_KEYUP, 0) if __name__ == "__main__": #win = win32ui.FindWindow(None, sys.argv[2]) #add another argument with window name and comment out the next line if you want only a specific window win = win32ui.GetForegroundWindow() win.SetForegroundWindow() win.SetFocus() sendKey(sys.argv[1])
def gotResultsInit(self,words,fullResults): if not self.txt: Cwnd = win32ui.GetForegroundWindow() self.txt=Cwnd.GetDlgItem(15008) # edit box
def get_cur_window_data(prev_exe, prev_file, prev_project): """ # Window たタイトルバーから情報を取得 s@prev_exe : s@prev_file : s@prev_project : """ cur_exe = '' #cur_exe = prev_exe cur_file = '' #cur_file = prev_file cur_project = prev_project # exe try: pid = win32process.GetWindowThreadProcessId( win32gui.GetForegroundWindow() ) #This produces a list of PIDs active window relates to cur_exe = psutil.Process(pid[-1]).name( ) #pid[-1] is the most likely to survive last longer # psutil.Process( pid[-1] ).exe() # get absolute path except Exception as except_inst: err_msg = str(except_inst).decode('shift_jis') logging.error(err_msg) logging.error(traceback.format_exc()) # window_text window_text = '' try: window_text = win32ui.GetForegroundWindow().GetWindowText() except Exception as except_inst: err_msg = str(except_inst).decode('shift_jis') if err_msg == 'No window is is in the foreground.': # = desktop pass else: logging.error(err_msg) logging.error(traceback.format_exc()) window_text = re.sub(r'\\', r'/', window_text) # get project file_path_search = self.pri_file_path_fmt.search(window_text) get_pri = 0 if file_path_search != None: # primary drive = file_path_search.group('drive') if not drive in self.ignore_drive_list: cur_project = file_path_search.group('project') get_pri = 1 if not cur_project in self.active_project_list: self.active_project_list.append(cur_project) if not get_pri: # secondary # and cur_project == prev_project for file_path_fmt in self.sec_file_path_fmt_list: file_path_search = file_path_fmt.search(window_text) if file_path_search != None: cur_project = file_path_search.group('project') break # 優先度の高いものから取得 # file name file_name_search = self.file_name_fmt.search(window_text) if file_name_search != None: ext = file_name_search.group('ext') cur_file = file_name_search.group('filename') cur_file = '{0}.{1}'.format(cur_file, ext) #print window_text #print 'prj={0}, exe={1}, file={2}'.format( cur_project, cur_exe, cur_file ) self.signal.main_set_current_project_signal.emit(cur_project) return cur_exe, cur_file, cur_project