Function Keys

  • Thread starter Thread starter One
  • Start date Start date
Hi One

Use the following in the KeyDown event handler.

Dim S as String
S = e.KeyCode & ", " & e.KeyValue & ", " & e.KeyData & ", " &
e.Shift

You'll see what happens for the function keys.

Then check out System.Windows.Forms.Keys which is an enumeration
containing constant values for you to use.

Regards,
Fergus
 
Hello,

One said:
how to get function keys(F1 to F12) when they are
pressed?

Set the form's 'KeyPreview' property to 'True', then add this code to your
form (assuming the form's class name is 'Form1'):

\\\
Private Sub Form1_KeyDown( _
ByVal sender As Object, _
ByVal e As System.Windows.Forms.KeyEventArgs _
) Handles MyBase.KeyDown
If e.KeyCode = Keys.F2 Then
MsgBox("F2 pressed!")
End If
End Sub
///

HTH,
Herfried K. Wagner
 
One,
In addition to overriding the KeyDown event, if you have a Menu on your form
you can assign the function keys to a MenuItem.

Remember: You can assign the function keys to a MenuItem that has its
Visible property set to false, and it will still work!

See the Shortcut property of a MenuItem, along with the Visible property if
needed.

Then you can simply handle the Click event for the MenuItem.

Hope this helps
Jay
 
Back
Top