-1

I'm trying to make a software in c# that needs to sendkeys.send the windows key and l how would i do this ive tried sendkeys.send(keys.lwin); but that doesn't work

MEZYPLAYS
  • 11
  • 2

1 Answers1

0

Here is a workaround that you can use the key combination Ctrl + Esc to replace Windows Key. The following is a simple demo.

private void btnSend_Click(object sender, EventArgs e)
{
    SendKeys.Send("^{ESC}");
}

Hope this can help you.


Modified:

If you want to lock the PC via code, you can call LockWorkStation function.

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

private void button1_Click(object sender, EventArgs e)
{
    LockWorkStation();
}

Besides, if you want achieve Win+D, Win+E, etc., you can try the following code.

[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);
}
大陸北方網友
  • 3,696
  • 3
  • 12
  • 37