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
Asked
Active
Viewed 339 times
-1
-
2Does this answer your question? [Sending Windows key using SendKeys](https://stackoverflow.com/questions/10366152/sending-windows-key-using-sendkeys) – NetMage Apr 16 '20 at 18:47
-
no this doesnt i does tell me how to do it. it just tells me about control & alt – MEZYPLAYS Apr 16 '20 at 20:35
-
Read the answers more closely. – NetMage Apr 16 '20 at 20:43
1 Answers
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
-
this would not work due to that only shows up the search bar and i dont want it to do that i want it so that i can lock my screen using it – MEZYPLAYS Apr 17 '20 at 11:56
-
-
-
@MEZYPLAYS I am glad this answer can help you. Maybe you can click `√` to accept the answer. – 大陸北方網友 Apr 22 '20 at 01:12