SetWindowsHookEx() WM_KEYBOARD_LL not coming through with full screen RDC

半腔热情 提交于 2019-12-18 17:56:50

问题


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.


回答1:


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




回答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.



来源:https://stackoverflow.com/questions/14596117/setwindowshookex-wm-keyboard-ll-not-coming-through-with-full-screen-rdc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!