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
Printable View
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
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 }
so is there anyway i can recognise when the user presses 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.
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)
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;
}
}