Class WinEventHook
Helps with UI element event hooks. See API SetWinEventHook.
public sealed class WinEventHook : IDisposable
Remarks
The thread that uses hooks must process Windows messages. For example have a window/dialog/messagebox, or use a "wait-for" function that dispatches messages or has such option (see Seconds.DoEvents).
important
The variable should be disposed when don't need, or at least unhooked, either explicitly (call Dispose or Unhook in same thread) or with using
. Can do it in hook procedure.
Examples
bool stop = false;
using var hook = new WinEventHook(EEvent.SYSTEM_FOREGROUND, 0, x => {
print.it(x.w);
var e = x.GetElm();
print.it(e);
if(x.w.ClassNameIs("Shell_TrayWnd")) stop = true;
});
dialog.show("hook");
//or
//wait.doEventsUntil(-10, () => stop); //wait max 10 s for activated taskbar
//print.it("the end");
Namespace: Au.More
Assembly: Au.dll
Constructors
Name | Description |
---|---|
WinEventHook(EEvent, EEvent, Action<WinEvent>, int, int, EHookFlags) | Sets a hook for an event or a range of events. |
WinEventHook(EEvent[], Action<WinEvent>, int, int, EHookFlags) | Sets multiple hooks. |
Methods
Name | Description |
---|---|
Add(EEvent, EEvent, int, int, EHookFlags) | Adds a hook for an event or a range of events. |
Dispose() | Calls WinEventHook.Unhook. |
Hook(EEvent, EEvent, int, int, EHookFlags) | Sets a hook for an event or a range of events. |
Hook(EEvent[], int, int, EHookFlags) | Sets multiple hooks. |
Remove(int) | Removes a hook added by WinEventHook.Add. |
Unhook() | Removes all hooks. |