Sendkeys for Windows Start键

时间:2014-06-10 04:17:29

标签: c# sendkeys

我尝试使用Sendkeys模拟Windows开始键,但我尝试过的选项都没有,有人知道怎么做?

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}");
    }

1 个答案:

答案 0 :(得分:4)

改为使用keybd_event

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(你要找的是0x5B - 左赢钥匙)