3

I'm trying to use the Sendkeys to simulate the Windows start key, but none of the options I tried work, does anybody know how can it be done?

CODE

    [System.Runtime.InteropServices.DllImport("user32.dll")]
    private Thread thrTyping;

    private void startThread()
    {
        ThreadStart ts = new ThreadStart(sendKeys);
        thrTyping = new Thread(ts);
        thrTyping.Start();
    }

    private void sendKeys()
    {
       // TEST 1
       Thread.Sleep(5000);
       SendKeys.SendWait("(^)"+"{ESC}");           

       // TEST 2
       Thread.Sleep(5000);
       SendKeys.SendWait("{LWin}");
    }
Ullas
  • 11,450
  • 4
  • 33
  • 50
AJ152
  • 671
  • 2
  • 12
  • 28

1 Answers1

4

Use keybd_event instead:

private const int KEYEVENTF_EXTENDEDKEY = 0x1;
private const int KEYEVENTF_KEYUP = 0x2;

[DllImport("user32.dll")]
static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, int dwExtraInfo);

private static void PressKey(byte keyCode)
{
    keybd_event(keyCode, 0x45, KEYEVENTF_EXTENDEDKEY, 0);
    keybd_event(keyCode, 0x45, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
}

List of KeyCodes (The one you are looking for is 0x5B - left win key)

Tzah Mama
  • 1,547
  • 1
  • 13
  • 25