0

Assume that i am creating a button for counter application, here i need to click the button with the help of a keyboard key instead of mouse click. Anyone can help with that function.

3 Answers3

0

If you are working on windows app You should add an event to the form, where the user is expected to press the key Right click on the object that should receive the key press (the body of the form) Go to properties page Click on the thunder icon (Events) Go to the KEY section Double click on Key Down Write the following:

if (e.KeyValue == 65) MessageBox.Show("You clicked the letter A. Code of B is 66, and so on");

To discover the KeyValue of the key pressed by the user:

MessageBox.Show(e.KeyValue.ToString());
Bak Stak
  • 127
  • 3
  • 16
Joe
  • 879
  • 3
  • 14
  • 37
0

If you want to use Alt + A instead of button , which is access key for your button you can refer to the https://msdn.microsoft.com/en-in/library/ms178233.aspx

0

As said in another answer Alt + the key is a button shortcut. One way in WinForms is to stick & in front of the character in the button text that you want to use to activate the button. E.g. if the button text is "ABC", change it to "&ABC". Then Alt-A can be used to activate the button. & is how button shortcuts are defined.

For WPF use AccessText or, without using Alt, key bindings: Assign Short Cut Key to a button in WPF

Daniel S. Fowler
  • 1,982
  • 15
  • 12