|
-
Dec 11th, 2006, 12:03 PM
#1
Thread Starter
Hyperactive Member
recognising the f keys???
im using ascii codes to recognise when the user presses keys 1-9, how can i recognise when the user presses keys f1 - f12??
thanks
GTJ
-
Dec 11th, 2006, 02:40 PM
#2
Re: recognising the f keys???
Those are special function keys and are not sectioned under alphanumeric keys. ASCII values are only assigned to alphanumeric keys.
You have to use KeyEventArgs.KeyCode or KeyEventArgs.KeyValue to check which key of the keyboard is pressed.
VB Code:
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
MessageBox.Show(e.KeyCode.ToString()); 'returns string value of the key pressed
MessageBox.Show(e.KeyValue.ToString()); 'returns keyboard value of the key
}
Last edited by Harsh Gupta; Dec 12th, 2006 at 08:39 AM.
-
Dec 12th, 2006, 07:22 AM
#3
Thread Starter
Hyperactive Member
Re: recognising the f keys???
so is there anyway i can recognise when the user presses the f keys??
-
Dec 12th, 2006, 08:56 AM
#4
Re: recognising the f keys???
That's what KeyCode or KeyValue meant for!! Under the KeyDown or KeyUp event of your control, use these properties to check which function key is pressed.
-
Dec 13th, 2006, 04:21 PM
#5
Thread Starter
Hyperactive Member
Re: recognising the f keys???
yer yer yer, i used your code and no messagebox comes up when i press the f keys!!! (a messagebox does come up for every other key)
-
Dec 13th, 2006, 05:32 PM
#6
Re: recognising the f keys???
Make sure you set the KeyPreview property of the form to True:
Code:
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
switch (e.KeyCode)
{
case Keys.F1:
break;
case Keys.F2:
break;
case Keys.F3:
break;
case Keys.F4:
break;
case Keys.F5:
break;
case Keys.F6:
break;
case Keys.F7:
break;
case Keys.F8:
break;
case Keys.F9:
break;
case Keys.F10:
break;
case Keys.F11:
break;
case Keys.F12:
break;
}
}
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
|