我知道如何使用SendKeys(),但如果我想模拟按住ESCAPE键5秒钟,我该怎么做呢?
解决方法@H_301_4@
您可以PInvoke keybd_event并按住Escape键5秒钟然后释放它:
[DllImport("user32.dll")]
static extern void keybd_event(byte bVk,byte bScan,uint dwFlags,UIntPtr dwExtraInfo);
keybd_event(VK_ESCAPE,0) // KEY_DOWN
System.Threading.Thread.Sleep(5000);
keybd_event(VK_ESCAPE,KEYEVENTF_KEYUP,0) // KEY_UP
[DllImport("user32.dll")] static extern void keybd_event(byte bVk,byte bScan,uint dwFlags,UIntPtr dwExtraInfo); keybd_event(VK_ESCAPE,0) // KEY_DOWN System.Threading.Thread.Sleep(5000); keybd_event(VK_ESCAPE,KEYEVENTF_KEYUP,0) // KEY_UP