Oct 29 2008

SendKeys in C#

Category: C#Bil@l @ 09:46

I had a need to execute some Windows Keystrokes in an application we are developing inside Windows Explorer, it is a Shell Namespace Extension, a virtual drive for an in-house EDMS. The keystroke to execute was an "F5" key. In other words, after performing an operation, I wanted to programamtically hit F5.

I posted on one of the forums and they refered me to this article: SendKeys in C++. It happened that this article is also written by a Lebanese guy, Elie :)

So I read this article and tried to search for SendKeys in C# and found a link to the System.Windows.Forms.SendKeys class that you can reach here: SendKeys in C#. Not only this class can be used within Windows Applications, but also within applications developed against Windows operating system itself, mainly a Shell Namespace Extension.

The way to execute a keystroke is simply call the following:

SendKeys.Send("{F5}");

 

That's all what you need to do!

Regards

Tags:

Comments are closed