Use class `WinEventHook`.
If you want to use it in the `@Triggers and toolbars` process (together with your keyboard/mouse/autotext/window triggers), a good place for the code is file `Other triggers`, or a file like it in the same folder. To open or create-open the file, click menu `TT > Other triggers`.
Example. A function in file `Other triggers`.
//this function runs at startup, and sets one or more UI element event hooks
[Triggers]
void WinEventTriggers() {
var hook = new WinEventHook(EEvent.SYSTEM_FOREGROUND, 0, x => {
//this code runs when an UI object event occurs (in this case - a window activated)
print.it(x.event_, x.w);
//var e = x.GetElm();
//print.it(e);
});
//example for multiple events
var hook2 = new WinEventHook([EEvent.SYSTEM_MINIMIZESTART, EEvent.SYSTEM_MINIMIZEEND], x => {
print.it(x.event_, x.w);
//var e = x.GetElm();
//print.it(e);
});
}
This can be useful to discover events. Run as a separate script.
// script "Log UI element events.cs"
print.clear();
var wLa = wnd.find(0, "LibreAutomate", "HwndWrapper[Au.Editor;*");
var wLaOutput = wLa.Child(0, "Output_text", "Scintilla");
int i = 0;
using var hook = new WinEventHook(EEvent.MIN, EEvent.MAX, x => {
//skip some unwanted events
if (x.w == wLaOutput) return;
if (x.idObject == EObjid.CURSOR) return;
//if (x.event_ == EEvent.OBJECT_LOCATIONCHANGER) return; //example - skip an event type
print.it(++i, x.event_, x.w);
//var e = x.GetElm();
//print.it(e);
}, flags: EHookFlags.SKIPOWNPROCESS);
dialog.show("Logging UI element events", "Close me to stop.");
[/code]