4

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?

0

3 Answers 3

7

I would use the SendKeys class, documented here.

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

SendKeys.Send("{ESC}"); 
Sign up to request clarification or add additional context in comments.

Comments

3

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

5 Comments

I have installed that package using nuget in my project. And I have also added using system.windows.input; on top of my code. but when i use this InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN); it says, windowsinputSimulator does not contain definiton of simulate key press. Can you please tell me what I am doing wrong?
What platform are you using? WinForms?
I am using WPF C#. I have a file called MainWindow.xaml.cs and yes I am using windows forms too inside.
I just looked at my project where I used this and the import statement was using WindowsInput; - not using system.windows.input;
If anybody is interested, it works perfect with Unity3D :)
-2

on the client side, use the jQuery.trigger command

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.