How to press the Windows button programmatically using C# SendKeys

前端 未结 3 1540
故里飘歌
故里飘歌 2021-01-12 04:02

Basically I want to simulate in code a user clicking on the windows button. I know there is SendKeys which allows me to send key presses to windows if I get a handle to them

3条回答
  •  旧巷少年郎
    2021-01-12 04:41

    Some of the things that a user would do via a WinKey shortcut can be done programmatically in other ways. To take your WinKey+L example, you could instead just use the following statement:

    Process.Start("rundll32.exe", "user32.dll,LockWorkStation");
    

    If you could elaborate on what exactly you're trying to accomplish, maybe there's a better way than keybd_event (as Dale has suggested).

提交回复
热议问题