How to simulate keypress
I know how to use SendKeys() but 开发者_JAVA百科how do i go about it if i would like to simulate holding ESCAPE key for like 5 seconds?
You can PInvoke keybd_event
and hold down Escape key for 5 seconds and then release it:
[DllImport("user32.dll")]
static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, UIntPtr dwExtraInfo);
keybd_event(VK_ESCAPE, 0, 0, 0) // KEY_DOWN
System.Threading.Thread.Sleep(5000);
keybd_event(VK_ESCAPE, 0, KEYEVENTF_KEYUP, 0) // KEY_UP
try using a timer... use System.Forms.Timer... for 5000ms... then if the 5000ms is finished, shut the timer off..
精彩评论