如何使用 sendkeys.send 来配合 windows 键
How do I use the sendkeys.send to work with the windows key
我正在尝试用 c# 制作一个需要 sendkeys.send windows 键的软件,我该怎么做我试过了 sendkeys.send(keys.lwin );但这不起作用
这是一个解决方法,您可以使用组合键 Ctrl + Esc
来替换 Windows Key
。下面是一个简单的demo。
private void btnSend_Click(object sender, EventArgs e)
{
SendKeys.Send("^{ESC}");
}
希望对您有所帮助。
修改:
如果你想通过代码锁定PC,你可以调用LockWorkStation function
。
[DllImport("user32 ")]
public static extern bool LockWorkStation();
private void button1_Click(object sender, EventArgs e)
{
LockWorkStation();
}
此外,如果你想实现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);
}
我正在尝试用 c# 制作一个需要 sendkeys.send windows 键的软件,我该怎么做我试过了 sendkeys.send(keys.lwin );但这不起作用
这是一个解决方法,您可以使用组合键 Ctrl + Esc
来替换 Windows Key
。下面是一个简单的demo。
private void btnSend_Click(object sender, EventArgs e)
{
SendKeys.Send("^{ESC}");
}
希望对您有所帮助。
修改:
如果你想通过代码锁定PC,你可以调用LockWorkStation function
。
[DllImport("user32 ")]
public static extern bool LockWorkStation();
private void button1_Click(object sender, EventArgs e)
{
LockWorkStation();
}
此外,如果你想实现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);
}