SetWindowsHookEx() WM_KEYBOARD_LL not coming through with full screen RDC
Asked Answered
A

2

4

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_KEYBOARD_LL which works fine. That is until you open a RDC connection and have it full screen. Then I never get the keyboard events.

Anyone come across this? Or know of a better way to achieve this? I have actually tested skype and with a full screen RDC it will correctly go from Away to Online if I type in the RDC.

Thanks

EDIT: After Raymond Chen's comment I did some testing, and he is right. Can not believe I never found this method after all my searching. It also solved an issue I was having with a WPF app not triggering the LL_Mouse/KEYBOARD events.

Thanks Again. Update my accepted answer based on this. The other answer is still good if you need to do LL_MOUSE/KWYBOARD.

Auction answered 30/1, 2013 at 3:19 Comment(0)
D
4

Have a look at GetLastInputInfo(). Try calling that periodically.

Dihydrostreptomycin answered 30/1, 2013 at 20:59 Comment(0)
G
2

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.

Groce answered 30/1, 2013 at 3:22 Comment(6)
Yay thanks. That did work. Although I also found a slightly different way. I use EVENT_SYSTEM_FOREGROUND event with SetWinEventHook() to get notified of window cahnges and then use OpenInputDesktop() to see if the desktop has changedAuction
great, that's also good trick. as I said that was my very old code and that days I found that way myself, I was tired of searching entire internet for it, no solution found. It backs to about 2006. But glad it still works and solved your problem.Groce
Yeh, the biggest tip there was that you have to reset the hooks on the change of desktop. I had found nothing else telling me that! So thanks again.Auction
This works only until two apps use this trick. Then they end up fighting with each other in order to be "first". The correct solution is GetLastInputInfo as noted in another answer.Wirra
That API doesn't return pressed key and also calling that API eventually like every 100 millisecond to capture user's input will exhause process memory and not a good ideaGroce
@VahidFarahmand Why would an API function leak memory every time it's called? I don't think that is the case. And that function isn't needed to get the pressed key, you still restart the hook as explained.Beaverboard

© 2022 - 2024 — McMap. All rights reserved.