Is it possible to create a listener that listens every time a window losses focus in WindowsOS and then runs the callback function? I am using win32api, win32net, wmi, win32gui, win32process. I am using GetActiveWindow() to get info i need but i am doing this with a sleep timer and i was wondering maybe there is a listner to which i could attach a handler to handle every time the window focus is changed for any window in WindowsOS.
Asked
Active
Viewed 2,185 times
2
-
This is more detailed example of using `SetWinEventHook` in Python: https://stackoverflow.com/questions/15849564/how-to-use-winapi-setwineventhook-in-python – Vasily Ryabov Apr 07 '15 at 14:10
1 Answers
1
SetWinEventHook(EVENT_OBJECT_FOCUS, EVENT_OBJECT_FOCUS, 0, HandleWinEvent, 0, 0, WINEVENT_OUTOFCONTEXT )
void CALLBACK HandleWinEvent(HWINEVENTHOOK /*hook*/, DWORD event, HWND hwnd,
LONG /*idObject*/, LONG /*idChild*/,
DWORD dwEventThread, DWORD dwmsEventTime)
{
if (event == EVENT_OBJECT_FOCUS )
{
DbgPrint("%u:%x %p\n", dwmsEventTime, dwEventThread, hwnd);
}
}

sutol
- 154
- 4