Use SendInput to lock the computer

偶尔善良 提交于 2019-12-10 23:09:24

问题


I want to use SendInput via C++ to lock the computer (Windows+L). I have created simple keyDown / keyUp functions in which I use SendInput to send a VK. On keyUp, it adds the flag 0x0002

I can simulate my tab key, my windows key and now I try to lock my computer with a simulated key stroke. I send the following messages:

key down:  0x5B (win key)
key down:  0x4C (L)
key up:    0x4C (L)
key up:    0x5B (win key)

My problem: Nothing happens :-(

Does someone know whats the solution?


回答1:


If I am not mistaken, you will not be able to do this with SendInput() (or keybd_event()) because it simply injects the keys into the keyboard input buffer, but special key sequences like CTRL+ALT+DEL, WIN+L, etc operate at a lower layer that are interpretted by the OS before keys are put in the input buffer.

The correct way to lock the computer is to use the LockWorkStation() function instead.



来源:https://stackoverflow.com/questions/11696253/use-sendinput-to-lock-the-computer

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