Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simulating Key Press in C# [duplicate]

So I want to make my program automatically simulate a key press after a timer stops. I have the timer and every setup already I just need to somehow simulate a key press. After a download message pops up on a web browser in the application I just want the program to simulate as "ESC" key press to exit out of the download message popup. How would I simulate the key press?

like image 969
user3026404 Avatar asked Oct 17 '25 14:10

user3026404


2 Answers

I would use the SendKeys class, documented here.

To send an 'Esc' keypush, for example, you would write:

SendKeys.Send("{ESC}");
like image 90
Baldrick Avatar answered Oct 20 '25 05:10

Baldrick


I would use the Windows Input Simulator as it is more reliable than Sendkeys.

like image 43
OneFineDay Avatar answered Oct 20 '25 05:10

OneFineDay