Python win32gui.PostMessage() Examples
The following are 30
code examples of win32gui.PostMessage().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
win32gui
, or try the search function
.
Example #1
Source File: inputs.py From NGU-scripts with GNU Lesser General Public License v3.0 | 10 votes |
def ctrl_click(x :int, y :int) -> None: """Clicks at pixel x, y while simulating the CTRL button to be down.""" x += Window.x y += Window.y lParam = win32api.MAKELONG(x, y) while (win32api.GetKeyState(wcon.VK_CONTROL) < 0 or win32api.GetKeyState(wcon.VK_SHIFT) < 0 or win32api.GetKeyState(wcon.VK_MENU) < 0): time.sleep(0.005) win32gui.PostMessage(Window.id, wcon.WM_KEYDOWN, wcon.VK_CONTROL, 0) win32gui.PostMessage(Window.id, wcon.WM_LBUTTONDOWN, wcon.MK_LBUTTON, lParam) win32gui.PostMessage(Window.id, wcon.WM_LBUTTONUP, wcon.MK_LBUTTON, lParam) win32gui.PostMessage(Window.id, wcon.WM_KEYUP, wcon.VK_CONTROL, 0) time.sleep(userset.MEDIUM_SLEEP)
Example #2
Source File: win32gui_dialog.py From ironpython2 with Apache License 2.0 | 9 votes |
def OnCommand(self, hwnd, msg, wparam, lparam): id = win32api.LOWORD(wparam) if id == IDC_BUTTON_SEARCH: self.ClearListItems() def fill_slowly(q, hwnd): import time for i in range(20): q.put(("whatever", str(i+1), "Search result " + str(i) )) win32gui.PostMessage(hwnd, WM_SEARCH_RESULT, 0, 0) time.sleep(.25) win32gui.PostMessage(hwnd, WM_SEARCH_FINISHED, 0, 0) import threading self.result_queue = Queue.Queue() thread = threading.Thread(target = fill_slowly, args=(self.result_queue, self.hwnd) ) thread.start() elif id == IDC_BUTTON_DISPLAY: print "Display button selected" sel = win32gui.SendMessage(self.hwndList, commctrl.LVM_GETNEXTITEM, -1, commctrl.LVNI_SELECTED) print "The selected item is", sel+1 # These function differ based on how the window is used, so may be overridden
Example #3
Source File: win32gui_taskbar.py From ironpython2 with Apache License 2.0 | 9 votes |
def OnTaskbarNotify(self, hwnd, msg, wparam, lparam): if lparam==win32con.WM_LBUTTONUP: print "You clicked me." elif lparam==win32con.WM_LBUTTONDBLCLK: print "You double-clicked me - goodbye" win32gui.DestroyWindow(self.hwnd) elif lparam==win32con.WM_RBUTTONUP: print "You right clicked me." menu = win32gui.CreatePopupMenu() win32gui.AppendMenu( menu, win32con.MF_STRING, 1023, "Display Dialog") win32gui.AppendMenu( menu, win32con.MF_STRING, 1024, "Say Hello") win32gui.AppendMenu( menu, win32con.MF_STRING, 1025, "Exit program" ) pos = win32gui.GetCursorPos() # See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/menus_0hdi.asp win32gui.SetForegroundWindow(self.hwnd) win32gui.TrackPopupMenu(menu, win32con.TPM_LEFTALIGN, pos[0], pos[1], 0, self.hwnd, None) win32gui.PostMessage(self.hwnd, win32con.WM_NULL, 0, 0) return 1
Example #4
Source File: inputs.py From NGU-scripts with GNU Lesser General Public License v3.0 | 7 votes |
def click_drag(x :int, y :int, x2 :int, y2 :int) -> None: """Click at pixel xy.""" x += Window.x y += Window.y x2 += Window.x y2 += Window.y lParam = win32api.MAKELONG(x, y) lParam2 = win32api.MAKELONG(x2, y2) # MOUSEMOVE event is required for game to register clicks correctly win32gui.PostMessage(Window.id, wcon.WM_MOUSEMOVE, 0, lParam) while (win32api.GetKeyState(wcon.VK_CONTROL) < 0 or win32api.GetKeyState(wcon.VK_SHIFT) < 0 or win32api.GetKeyState(wcon.VK_MENU) < 0): time.sleep(0.005) win32gui.PostMessage(Window.id, wcon.WM_LBUTTONDOWN, wcon.MK_LBUTTON, lParam) time.sleep(userset.LONG_SLEEP * 2) win32gui.PostMessage(Window.id, wcon.WM_MOUSEMOVE, 0, lParam2) time.sleep(userset.SHORT_SLEEP) win32gui.PostMessage(Window.id, wcon.WM_LBUTTONUP, wcon.MK_LBUTTON, lParam2) time.sleep(userset.MEDIUM_SLEEP)
Example #5
Source File: SysTrayIcon.py From LIFX-Control-Panel with MIT License | 7 votes |
def show_menu(self): menu = win32gui.CreatePopupMenu() self.create_menu(menu, self.menu_options) # win32gui.SetMenuDefaultItem(menu, 1000, 0) pos = win32gui.GetCursorPos() # See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/menus_0hdi.asp win32gui.SetForegroundWindow(self.hwnd) win32gui.TrackPopupMenu(menu, win32con.TPM_LEFTALIGN, pos[0], pos[1], 0, self.hwnd, None) win32gui.PostMessage(self.hwnd, win32con.WM_NULL, 0, 0)
Example #6
Source File: gui.py From peach with Mozilla Public License 2.0 | 7 votes |
def enumCallback(hwnd, self): title = win32gui.GetWindowText(hwnd) for name in self.WindowNames: if title.find(name) > -1: try: self.FoundWindowEvent.set() if self.CloseWindows: win32gui.PostMessage(hwnd, win32con.WM_CLOSE, 0, 0) except: pass else: try: win32gui.EnumChildWindows(hwnd, _WindowWatcher.enumChildCallback, self) except: pass return True
Example #7
Source File: __init__.py From pyrexecd with MIT License | 6 votes |
def _notify(klass, hwnd, msg, wparam, lparam): self = klass._instance[hwnd] if lparam == win32con.WM_LBUTTONDBLCLK: menu = self.get_popup() wid = win32gui.GetMenuDefaultItem(menu, 0, 0) if 0 < wid: win32gui.PostMessage(hwnd, win32con.WM_COMMAND, wid, 0) elif lparam == win32con.WM_RBUTTONUP: menu = self.get_popup() pos = win32gui.GetCursorPos() win32gui.SetForegroundWindow(hwnd) win32gui.TrackPopupMenu( menu, win32con.TPM_LEFTALIGN, pos[0], pos[1], 0, hwnd, None) win32gui.PostMessage(hwnd, win32con.WM_NULL, 0, 0) elif lparam == win32con.WM_LBUTTONUP: pass return True
Example #8
Source File: tray.py From MouseTracks with GNU General Public License v3.0 | 6 votes |
def show_menu(self): """Draw the popup menu.""" menu = win32gui.CreatePopupMenu() self._create_menu(menu, self.menu_options) pos = win32gui.GetCursorPos() # See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/menus_0hdi.asp win32gui.SetForegroundWindow(self.hwnd) win32gui.TrackPopupMenu(menu, win32con.TPM_LEFTALIGN, pos[0], pos[1], 0, self.hwnd, None) win32gui.PostMessage(self.hwnd, win32con.WM_NULL, 0, 0) self.logger.debug('Menu displayed.')
Example #9
Source File: process.py From peach with Mozilla Public License 2.0 | 6 votes |
def enumChildCallback(hwnd, windowName): """ Will get called by win32gui.EnumWindows, once for each top level application window. """ try: # Get window title title = win32gui.GetWindowText(hwnd) # Is this our guy? if title.find(windowName) == -1: return # Send WM_CLOSE message win32gui.PostMessage(hwnd, win32con.WM_CLOSE, 0, 0) except: pass #print sys.exc_info()
Example #10
Source File: cutthecrap.py From fame_modules with GNU General Public License v3.0 | 6 votes |
def foreach_window(self): def callback(hwnd, lparam): title = win32gui.GetWindowText(hwnd).lower() for window in self.to_close: if window in title: win32gui.PostMessage(hwnd, win32con.WM_CLOSE, 0, 0) print "Closed window ({})".format(title) for window in self.clicks: if window in title: self._windows[hwnd] = { "matches": self.clicks[window], "to_click": [], "buttons": [] } try: win32gui.EnumChildWindows(hwnd, self.foreach_child(), hwnd) except: print "EnumChildWindows failed, moving on." for button_toclick in self._windows[hwnd]['to_click']: for button in self._windows[hwnd]['buttons']: if button_toclick in button['text']: win32gui.SetForegroundWindow(button['handle']) win32gui.SendMessage(button['handle'], win32con.BM_CLICK, 0, 0) print "Clicked on button ({} / {})".format(title, button['text']) del self._windows[hwnd] return True return callback
Example #11
Source File: process.py From peach with Mozilla Public License 2.0 | 6 votes |
def enumChildCallback(hwnd, windowName): """ Will get called by win32gui.EnumWindows, once for each top level application window. """ try: # Get window title title = win32gui.GetWindowText(hwnd) # Is this our guy? if title.find(windowName) == -1: return # Send WM_CLOSE message win32gui.PostMessage(hwnd, win32con.WM_CLOSE, 0, 0) except: pass #print sys.exc_info()
Example #12
Source File: file.py From peach with Mozilla Public License 2.0 | 6 votes |
def enumChildCallback(hwnd, args): """ Will get called by win32gui.EnumWindows, once for each top level application window. """ proc = args[0] windowName = args[1] try: # Get window title title = win32gui.GetWindowText(hwnd) # Is this our guy? if title.find(windowName) == -1: return # Send WM_CLOSE message win32gui.PostMessage(hwnd, win32con.WM_CLOSE, 0, 0) except: pass #print sys.exc_info()
Example #13
Source File: file.py From peach with Mozilla Public License 2.0 | 6 votes |
def enumCallback(hwnd, args): """ Will get called by win32gui.EnumWindows, once for each top level application window. """ proc = args[0] windowName = args[1] try: # Get window title title = win32gui.GetWindowText(hwnd) # Is this our guy? if title.find(windowName) == -1: win32gui.EnumChildWindows(hwnd, FileWriterLauncherGui.enumChildCallback, args) return # Send WM_CLOSE message win32gui.PostMessage(hwnd, win32con.WM_CLOSE, 0, 0) except: pass
Example #14
Source File: systray.py From OpenBazaar-Installer with MIT License | 6 votes |
def show_menu(self): menu = win32gui.CreatePopupMenu() self.create_menu(menu, self.menu_options) # win32gui.SetMenuDefaultItem(menu, 1000, 0) pos = win32gui.GetCursorPos() # See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/menus_0hdi.asp win32gui.SetForegroundWindow(self.hwnd) win32gui.TrackPopupMenu(menu, win32con.TPM_LEFTALIGN, pos[0], pos[1], 0, self.hwnd, None) win32gui.PostMessage(self.hwnd, win32con.WM_NULL, 0, 0)
Example #15
Source File: gui_win.py From ComicStreamer with Apache License 2.0 | 6 votes |
def show_menu(self): menu = win32gui.CreatePopupMenu() self.create_menu(menu, self.menu_options) #win32gui.SetMenuDefaultItem(menu, 1000, 0) pos = win32gui.GetCursorPos() # See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/menus_0hdi.asp win32gui.SetForegroundWindow(self.hwnd) win32gui.TrackPopupMenu(menu, win32con.TPM_LEFTALIGN, pos[0], pos[1], 0, self.hwnd, None) win32gui.PostMessage(self.hwnd, win32con.WM_NULL, 0, 0)
Example #16
Source File: winapi.py From gui-o-matic with GNU Lesser General Public License v3.0 | 6 votes |
def _show_menu( self ): menu = win32gui.CreatePopupMenu() for action in self.menu_actions: if action: flags = win32con.MF_STRING if not action.sensitive: flags |= win32con.MF_GRAYED win32gui.AppendMenu( menu, flags, action.get_id(), action.label ) else: win32gui.AppendMenu( menu, win32con.MF_SEPARATOR, 0, '' ) pos = win32gui.GetCursorPos() win32gui.SetForegroundWindow( self.window_handle ) win32gui.TrackPopupMenu( menu, win32con.TPM_LEFTALIGN | win32con.TPM_BOTTOMALIGN, pos[ 0 ], pos[ 1 ], 0, self.window_handle, None ) win32gui.PostMessage( self.window_handle, win32con.WM_NULL, 0, 0 )
Example #17
Source File: winguiauto.py From pyautotrade_tdx with GNU General Public License v2.0 | 5 votes |
def click(hwnd): ''' 模拟鼠标左键单击 :param hwnd: 要单击的控件、窗体句柄 :return: ''' win32gui.PostMessage(hwnd, win32con.WM_LBUTTONDOWN, None, None) time.sleep(.2) win32gui.PostMessage(hwnd, win32con.WM_LBUTTONUP, None, None)
Example #18
Source File: ListCtrl.py From BitTorrent with GNU General Public License v3.0 | 5 votes |
def SelectColumn(self, col): """Color the selected column (MSW only)""" if self.selected_column == col: return col_num = self.enabled_columns.index(col) if os.name == 'nt': win32gui.PostMessage(self.GetHandle(), LVM_SETSELECTEDCOLUMN, col_num, 0) if self.selected_column is not None: self.RefreshCol(self.selected_column) self.RefreshCol(col) self.selected_column = col
Example #19
Source File: winguiauto.py From pyautotrade_tdx with GNU General Public License v2.0 | 5 votes |
def sendKey(hwnd, key_code): ''' 模拟按键 :param hwnd: 窗体句柄 :param key_code: 按键码,在win32con下,比如win32con.VK_F1 :return: ''' win32gui.PostMessage(hwnd, win32con.WM_KEYDOWN, key_code, 0) # 消息键盘 time.sleep(.2) win32gui.PostMessage(hwnd, win32con.WM_KEYUP, key_code, 0)
Example #20
Source File: winguiauto.py From pyAutoTrading with GNU General Public License v2.0 | 5 votes |
def click(hwnd): """ 模拟鼠标左键单击 :param hwnd: 要单击的控件、窗体句柄 :return: """ win32gui.PostMessage(hwnd, win32con.WM_LBUTTONDOWN, None, None) time.sleep(0.2) win32gui.PostMessage(hwnd, win32con.WM_LBUTTONUP, None, None) time.sleep(0.2)
Example #21
Source File: winguiauto.py From pyAutoTrading with GNU General Public License v2.0 | 5 votes |
def sendKeyMsg(hwnd, key_code): """ 模拟按键 :param hwnd: 窗体句柄 :param key_code: 按键码,在win32con下,比如win32con.VK_F1 :return: """ win32gui.PostMessage(hwnd, win32con.WM_KEYDOWN, key_code, 0) # 消息键盘 time.sleep(0.2) win32gui.PostMessage(hwnd, win32con.WM_KEYUP, key_code, 0) time.sleep(0.2)
Example #22
Source File: wts.py From code with MIT License | 5 votes |
def WinXPUnlockWorkstation(): hDesktop, hSasWindow = FindSasWindow() win32gui.PostMessage(hSasWindow, WM_LOGONNOTIFY, LN_UNLOCK_WORKSTATION, 0)
Example #23
Source File: window.py From openxenmanager with GNU General Public License v2.0 | 5 votes |
def signal_handler(self): """ Function called when oxc gets a signal """ print "Exiting..." for sh in self.xc_servers: self.xc_servers[sh].halt = True self.xc_servers[sh].halt_search = True self.xc_servers[sh].halt_performance = True self.xc_servers[sh].logout() self.config.write() if self.hWnd != 0: win32gui.PostMessage(self.hWnd, win32con.WM_QUIT, 0, 0) self.hWnd = 0
Example #24
Source File: window.py From openxenmanager with GNU General Public License v2.0 | 5 votes |
def on_window_destroy(self, widget, data=None): """ Function called when you close the window or press Quit """ # For each server if self.tunnel: for key in self.tunnel.keys(): self.tunnel[key].close() for sh in self.xc_servers: # Stop the threads setting True the condition variables self.xc_servers[sh].halt = True self.xc_servers[sh].halt_search = True self.xc_servers[sh].halt_import = True self.xc_servers[sh].halt_performance = True # Do a logout, remember logout disconnect to server and unregister events self.xc_servers[sh].logout() # For windows only: close the tightvnc console if self.hWnd != 0: win32gui.PostMessage(self.hWnd, win32con.WM_QUIT, 0, 0) self.hWnd = 0 # Get the position of the main window pane self.save_pane_position() # Save unsaved changes self.config.write() # Exit! gtk.main_quit() if self.vnc_process: for process in self.vnc_process.keys(): #Kill all running sub_processes if self.vnc_process[process].poll() != 0: os.killpg(os.getpgid(self.vnc_process[process].pid), signal.SIGTERM) #Force Quit os._exit(0) return
Example #25
Source File: inputs.py From NGU-scripts with GNU Lesser General Public License v3.0 | 5 votes |
def click(x :int, y :int, button :str ="left", fast :bool =False) -> None: """Click at pixel xy.""" x += Window.x y += Window.y lParam = win32api.MAKELONG(x, y) # MOUSEMOVE event is required for game to register clicks correctly win32gui.PostMessage(Window.id, wcon.WM_MOUSEMOVE, 0, lParam) while (win32api.GetKeyState(wcon.VK_CONTROL) < 0 or win32api.GetKeyState(wcon.VK_SHIFT) < 0 or win32api.GetKeyState(wcon.VK_MENU) < 0): time.sleep(0.005) if button == "left": win32gui.PostMessage(Window.id, wcon.WM_LBUTTONDOWN, wcon.MK_LBUTTON, lParam) win32gui.PostMessage(Window.id, wcon.WM_LBUTTONUP, wcon.MK_LBUTTON, lParam) else: win32gui.PostMessage(Window.id, wcon.WM_RBUTTONDOWN, wcon.MK_RBUTTON, lParam) win32gui.PostMessage(Window.id, wcon.WM_RBUTTONUP, wcon.MK_RBUTTON, lParam) # Sleep lower than 0.1 might cause issues when clicking in succession if fast: time.sleep(userset.FAST_SLEEP) else: time.sleep(userset.MEDIUM_SLEEP)
Example #26
Source File: winapi.py From gui-o-matic with GNU Lesser General Public License v3.0 | 5 votes |
def _signal_queue( self ): ''' signal that there are actions to process in the queue ''' win32gui.PostMessage( self.systray_window.window_handle, self.WM_USER_QUEUE, 0, 0 )
Example #27
Source File: __init__.py From pyrexecd with MIT License | 5 votes |
def close(self): self.logger.info('close') win32gui.PostMessage(self.hwnd, win32con.WM_CLOSE, 0, 0) return
Example #28
Source File: winguiauto.py From PyAutoTrading with GNU General Public License v2.0 | 5 votes |
def pressKey(hwnd, key_code): ''' 模拟按键 :param hwnd: 窗体句柄 :param key_code: 按键码,在win32con下,比如win32con.VK_F1 :return: ''' win32gui.PostMessage(hwnd, win32con.WM_KEYDOWN, key_code, 0) # 消息键盘 time.sleep(.2) win32gui.PostMessage(hwnd, win32con.WM_KEYUP, key_code, 0) time.sleep(.2)
Example #29
Source File: winguiauto.py From PyAutoTrading with GNU General Public License v2.0 | 5 votes |
def click(hwnd): ''' 模拟鼠标左键单击 :param hwnd: 要单击的控件、窗体句柄 :return: ''' win32gui.PostMessage(hwnd, win32con.WM_LBUTTONDOWN, None, None) time.sleep(.2) win32gui.PostMessage(hwnd, win32con.WM_LBUTTONUP, None, None) time.sleep(.2)
Example #30
Source File: process.py From peach with Mozilla Public License 2.0 | 5 votes |
def enumCallback(hwnd, windowName): """ Will get called by win32gui.EnumWindows, once for each top level application window. """ try: # Get window title title = win32gui.GetWindowText(hwnd) # Is this our guy? if title.find(windowName) == -1: win32gui.EnumChildWindows(hwnd, FileWriterLauncherGui.enumChildCallback, windowName) return # Send WM_CLOSE message win32gui.PostMessage(hwnd, win32con.WM_CLOSE, 0, 0) except: pass