Skip to content

Instantly share code, notes, and snippets.

@Misaka-0x447f
Last active September 8, 2018 06:21
Show Gist options
  • Save Misaka-0x447f/1e11d74c7a54c6f5a8420ff9aea954e9 to your computer and use it in GitHub Desktop.
Save Misaka-0x447f/1e11d74c7a54c6f5a8420ff9aea954e9 to your computer and use it in GitHub Desktop.
Press LWIN key in C#
public partial class Form1 : Form
{
[DllImport("user32.dll")]
private static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);
private const int KEYEVENTF_EXTENDEDKEY = 1;
private const int KEYEVENTF_KEYUP = 2;
public static void KeyDown(Keys vKey)
{
keybd_event((byte)vKey, 0, KEYEVENTF_EXTENDEDKEY, 0);
}
public static void KeyUp(Keys vKey)
{
keybd_event((byte)vKey, 0, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
}
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e) {
KeyDown(Keys.LWin);
KeyUp(Keys.LWin);
}
}
@Misaka-0x447f
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment