示例#1
0
        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");
        }
示例#2
0
 private void AttachWinEventHook(IWinEventCallbacks callbacks, uint pid)
 {
     if (messagePumpTask == null)
     {
         messagePumpDone = false;
         messagePumpTask = Task.Run(() => MessagePump(callbacks, pid));
     }
 }
示例#3
0
 public WinEventCallback(IWinEventCallbacks callbacks, uint pidOfInterest)
 {
     this.pid       = pidOfInterest;
     this.callbacks = callbacks;
 }
示例#4
0
 public WinEventSystem(IWinEventCallbacks callbacks, uint pid)
 {
     this.AttachWinEventHook(callbacks, pid);
 }
示例#5
0
 public WinEventSystem AttachWinEventSystem(IWinEventCallbacks callbacks)
 {
     return(new WinEventSystem(callbacks, (uint)this.pid));
 }