代码实现Win+Key

通过代码实现Win+D,Win+E等等,可以参考以下代码:

[DllImport("User32.dll")]
public static extern void keybd_event(Byte bVk, Byte bScan, Int32 dwFlags, Int32 dwExtraInfo);

private void button1_Click(object sender, EventArgs e)
{
    keybd_event(0x5b, 0, 0, 0);
    keybd_event(68, 0, 0, 0); // D is 68, and E is 69
    keybd_event(0x5b, 0, 0x2, 0);
    keybd_event(68, 0, 0x2, 0);
}

Virtual-Key Codes

注意:使用76(Win+L)时并不能实现锁屏。

实现锁屏,可以调用LockWorkStation方法

[DllImport("user32 ")]
public static extern bool LockWorkStation();

private void button1_Click(object sender, EventArgs e)
{
    LockWorkStation();
}
原文地址:https://www.cnblogs.com/jizhiqiliao/p/12737571.html