How to simulate keystrokes

I know how to use SendKeys (), but how to do it if I would like to simulate saving the ESCAPE key for 5 seconds?

+6
c #
source share
2 answers

You can PInvoke keybd_event and hold the Escape key for 5 seconds and then release:

 [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 
+13
source share

try using a timer ... use System.Forms.Timer ... for 5000ms ... and then if 5000ms is finished, turn off the timer ..

-2
source share

All Articles