Dhanapal
Dhanapal

Reputation: 14507

Is there a way to press or fireup the keys in key board using c# code?

I want the 'Alt' to be pressed by code. It is like firing key-press event with key 'Alt' by the code, not hitting it manually. The need is, I have set 'ShortCut keys for menu, but it (the single underline on key letter) is not visible to the user unless he presses 'alt'. So i need to make the Alt be pressed by default.

Is there a way to 'press' or 'fireup' the keys in key board using c# code?

Upvotes: 0

Views: 787

Answers (4)

Mark Rushakoff
Mark Rushakoff

Reputation: 258138

If you have any control over the operating system on which the program is being deployed, apparently you can force the underlined shortcut letter to always be displayed by going to Control Panel -> Display -> Appearance -> Effects -> Hide underlined letters for keyboard navigation.

(http://www.chinhdo.com/20080902/underlined-letters-windows/)

Upvotes: 2

Jasson
Jasson

Reputation: 259

Here is how you simulate input (both mouse and keyboard). http://msdn.microsoft.com/en-us/library/ms171548.aspx

If you look at the System.Windows.Forms.SendKeys class you will see that it provides you with what you want. http://msdn.microsoft.com/en-us/library/system.windows.forms.sendkeys.aspx

Upvotes: 1

TheVillageIdiot
TheVillageIdiot

Reputation: 40497

here is a complete article on use of SendKeys on codeproject

Upvotes: 1

Chris Thompson
Chris Thompson

Reputation: 16841

Check out the System.Windows.Forms.SendKeys class.

You can use the static Send method to send keystrokes to the active window. If you're trying to send keystrokes to another window, you'll need to use the Windows API to activate the other window first.

Upvotes: 3

Related Questions