开发者

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..

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜