We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

Detect Input Key, Convert value to DWORD

JoeD77
JoeD77 asked
on
Medium Priority
307 Views
Last Modified: 2012-05-11
Hello.
I'm trying to enable user input to configure hotkeys for an application, and I'm struggling with trying to detect when a key is pressed and subsequently retrieve the DWORD value pertaining to said pressed key.

I'm trying something like this:
 
        private void textBox1_TextChanged(object sender, KeyEventArgs e)
        {
            string result = String.Format("%d", e.KeyValue);
            MessageBox.Show(result);
        }

Open in new window


When I type in textBox1, nothing happens at all.

Ideally, I'd like the user to be able to click a button, and then enter in their input, which will be recorded as a DWORD value.

Any help would be great, thanks.
Comment
Watch Question

The TextChanged event only fires when you leave focus of the text box not when you are actually typing each key. For that you should use KeyDown, KeyUp or KeyPress events.

That is not the correct syntax for String.Format. You just use place holders like string result = String.Format("{0}", e.KeyValue); The conversion of what you pass in will get converted to a string automatically (using the ToString() method of object internally)

Author

Commented:
Thanks for your help, brutaldev.

Changed code to:
private void textBox1_KeyPress(object sender, KeyEventArgs e)
        {
            MessageBox.Show(e.KeyCode.ToString());
        }

Open in new window


Still displays nothing. _KeyDown has the same result.
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
Wonderful, thanks for noticing my ignorance :)!
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.