|
-
Apr 11th, 2006, 08:32 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Creating an event handler for a keyboard character
Hi guys. Is there any way to create an even handler for a keyboard key. e.g. similar to a normal event with a button. But now all I want is like to press a certain key, say 'm' and write some code when the user presses this key. Is there any way to do this? so let's say, the program is up and running, and when the user presses the 'm' key, a message box appears with "hello". Is there any way to do this?
Jennifer
-
Apr 11th, 2006, 09:04 AM
#2
Hyperactive Member
Re: Creating an event handler for a keyboard character
Code:
//
// In the constructor
//
AddEvent(this)
private void AddEvent(Control control)
{
control.KeyDown += new KeyEventHandler(control_KeyDown);
foreach (Control co in control.Controls)
{
AddEvent(co);
}
}
private void control_KeyDown(object sender, KeyEventArgs e)
{
//
// When the user presses 'm'(keyvalue 77) trigger the message box
//
if (e.KeyValue == 77)
{
MessageBox.Show("Hello");
}
}
-
Apr 11th, 2006, 09:38 AM
#3
Thread Starter
Hyperactive Member
Re: Creating an event handler for a keyboard character
Thanks hon, it worked fine!!!!
-
Apr 11th, 2006, 09:54 AM
#4
Hyperactive Member
Re: Creating an event handler for a keyboard character
Youre welcome, dont forget to mark it as resolved.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|