I know how to use SendKeys() but 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With