private void MessagePump(IWinEventCallbacks callbacks, uint pid) { Log.Comment("Accessibility message pump thread started"); WinEventCallback callback = new WinEventCallback(callbacks, pid); IntPtr hWinEventHook = User32.SetWinEventHook( User32.WinEventId.EVENT_CONSOLE_CARET, User32.WinEventId.EVENT_CONSOLE_END_APPLICATION, IntPtr.Zero, // Use our own module new User32.WinEventDelegate(callback.WinEventProc), // Our callback function 0, // All processes 0, // All threads User32.WinEventFlags.WINEVENT_SKIPOWNPROCESS | User32.WinEventFlags.WINEVENT_SKIPOWNTHREAD); NativeMethods.Win32NullHelper(hWinEventHook, "Registering accessibility event hook."); Log.Comment("Entering accessibility pump loop."); while (!messagePumpDone) { User32.MSG msg; if (User32.PeekMessage(out msg, IntPtr.Zero, 0, 0, User32.PM.PM_REMOVE)) { User32.DispatchMessage(ref msg); } Thread.Sleep(200); } Log.Comment("Exiting accessibility pump loop."); NativeMethods.Win32BoolHelper(User32.UnhookWinEvent(hWinEventHook), "Unregistering accessibility event hook."); Log.Comment("Accessibility message pump thread ended"); }
private void AttachWinEventHook(IWinEventCallbacks callbacks, uint pid) { if (messagePumpTask == null) { messagePumpDone = false; messagePumpTask = Task.Run(() => MessagePump(callbacks, pid)); } }
public WinEventCallback(IWinEventCallbacks callbacks, uint pidOfInterest) { this.pid = pidOfInterest; this.callbacks = callbacks; }
public WinEventSystem(IWinEventCallbacks callbacks, uint pid) { this.AttachWinEventHook(callbacks, pid); }
public WinEventSystem AttachWinEventSystem(IWinEventCallbacks callbacks) { return(new WinEventSystem(callbacks, (uint)this.pid)); }