What is the syntax for detecting function key events?

  • Thread starter Thread starter Sean Connery
  • Start date Start date
For any object that has the keyDown event, you can use (example for a form
named Form1):

private void Form1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs
e)
{
if (e.KeyCode == Keys.F1) DoSomething();
}

hope that helps....
Cata
 
Hi Sean,
There is no method in the framework to check the key state except for the
modifier keys (CTRL, SHIFT and ALT).
You have to use KeyDown/Up events or P\Invoke to use the API functions for
that.

B\rgds
100
 
For some reason, I am not snagging the event. I have created a base child
form where the derived child form is embedded within an MDI parent
container. The child form is in focus and when I press the appropriate
function key, no event is fired.

My test code looks as follows:


private void ChildViewBase_KeyDown(object sender,
System.Windows.Forms.KeyEventArgs e)
{
switch (e.KeyCode)
{
case Keys.F1:
F1KeyPressed();
break;
case Keys.F2:
F2KeyPressed();
break;
}

protected virtual void F1KeyPressed() {}
protected virtual void F2KeyPressed() {}
 
Back
Top