Input for Keystroke Combination

vendiddy

Well-known member
Joined
May 14, 2006
Messages
64
Programming Experience
1-3
I am trying to make a text box which displays the current keystroke combination the user is pressing. For example, if I press the control key, the alt key, and the S key, "Ctrl+Alt+S" will be displayed in the textbox.

In the VS IDE, if you go to Tools > Customize > Keyboard, and press a keystroke combination in the text box under "Press shortcut keys," you will see what kind of functionality I'm looking for.

One more thing, how would I save the keystroke combination to a variable. And, how could I convert this variable to a string if I wanted to save the user's settings to a text file?

Thanks. :cool:
 
Last edited:
In Textbox.KeyDown event you have this information available from e parameter e.Alt (Boolean) e.Control (Boolean) and e.KeyCode (Keys enum). You can create a class with these properties and provide conversion for String compound value.
 
Thanks. One more question: how can I display e.KeyCode as an enumeration? If I have txtShortcut.Text = e.KeyCode.ToString(), it isn't displayed in the proper format. For example pressing the D key displays "dD"
 
It's been a while since I responded to this thread, but the problem was that I didn't say e.SuppressKeyPress = True.
 
Back
Top