I’m trying to write a basic keylogger in C++ and so far I managed to install a low lever keyboard hook using the win api. It notifies me everytime a key is pressed.
I would like to do something similar to notify me every time the focus is changed to another window, so I know which window the user is typing in.
I tryed to set a HW_CBT hook but it doesn’t give me any notifications.
What is the best way to do this?
EDIT:
I have edded this code:
LRESULT CALLBACK CallWndProc(int nCode, WPARAM wParam, LPARAM lParam) {
cout<<"event";
return CallNextHookEx(0, nCode, wParam, lParam);
}
and SetWindowsHookEx(WH_CALLWNDPROC, CallWndProc, NULL, NULL);
I also have this in my program:
while(true)
GetMessage(&msg,0,WM_KEYFIRST, WM_KEYLAST);
I’m still not getting any notifications when I run the program, except for the ones about key strokes.
EDIT 2!!
I got it done using GetWindowText(), GetForegroundWindow() and a timer. Not really what I was looking for but this will do.
I’ll just accept the first answer…
Maybe this could be useful to you? SetWindowsHookEx
Installs a hook procedure that monitors messages before the system sends them to the destination window procedure