问题
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