I\'m trying to do a away timer style thing like Skype. If the user is \'away\' for a period of time I\'ll trigger something. I have been using SetWindowsHookEx() with WM_KEY
Have a look at GetLastInputInfo(). Try calling that periodically.
Yes. You'll not get keys pressed in remote desktop. I had this problem and only solution I found was this:
Using FindWindow API always look to find RDP window, if you've detected that full-screen RDP window has been created you should do this:
a) Unhook all hooks. b) Reset all hooks.
So create a function which makes SetWindowHookEx API calls and call it SetHook and another one as UnHook function. Then re-call both of them anytime you find out user get into remote desktop.
Now you can get keys pressed even inside remote desktop connection.
I found my old code, I did something like this:
Created a timer with 1 sec. Then
std::string tmp;
HWND hParent = ::FindWindow(TEXT("TSHELLHWND"), NULL);
GetWindowString(hParent, tmp);
ix = za.find(" - Remote Desktop");
if (hParent != NULL && ix != string::npos)
RestartHook();
You also should have a global variable to set when you've restarted hook, otherwise all the time it will restart the hook. When window closed, you can reset that global variable.