How to use winapi SetWinEventHook in python? -


i want handle of every new dialog pops specific application.
understand should set hook setwineventhook in user32.dll in windows, don't know how in python. give me example ?

here's simple example prints console window text each dialog opened:

import sys import time import ctypes import ctypes.wintypes  event_system_dialogstart = 0x0010 winevent_outofcontext = 0x0000  user32 = ctypes.windll.user32 ole32 = ctypes.windll.ole32  ole32.coinitialize(0)  wineventproctype = ctypes.winfunctype(     none,      ctypes.wintypes.handle,     ctypes.wintypes.dword,     ctypes.wintypes.hwnd,     ctypes.wintypes.long,     ctypes.wintypes.long,     ctypes.wintypes.dword,     ctypes.wintypes.dword )  def callback(hwineventhook, event, hwnd, idobject, idchild, dweventthread, dwmseventtime):     length = user32.getwindowtextlengtha(hwnd)     buff = ctypes.create_string_buffer(length + 1)     user32.getwindowtexta(hwnd, buff, length + 1)     print buff.value  wineventproc = wineventproctype(callback)  user32.setwineventhook.restype = ctypes.wintypes.handle hook = user32.setwineventhook(     event_system_dialogstart,     event_system_dialogstart,     0,     wineventproc,     0,     0,     winevent_outofcontext ) if hook == 0:     print 'setwineventhook failed'     sys.exit(1)  msg = ctypes.wintypes.msg() while user32.getmessagew(ctypes.byref(msg), 0, 0, 0) != 0:     user32.translatemessagew(msg)     user32.dispatchmessagew(msg)  user32.unhookwinevent(hook) ole32.couninitialize() 

Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

java Extracting Zip file -

C# WinForm - loading screen -