Welcome to Bilal Haidar [MVP, MCT] Official Blog Sign in | Join | Help

SendKeys in C#

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

Published Tuesday, October 28, 2008 11:46 PM by BilalHaidar [MVP]
Filed under:

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

No Comments

Leave a Comment

(required) 
required 
(required)