title: Capture function keys F1..F12 in VB.NET
body: <p>I cannot capture the function keys <kbd>F1</kbd>..<kbd>F12</kbd> for my application. I am able to capture regular keys and modifiers such as <kbd>shift</kbd>, <kbd>ctrl</kbd>, <kbd>alt</kbd>, etc..</p>
  
  <p>This <a href="https://stackoverflow.com/questions/1707040/handling-function-key-press">question</a> recommends <code>KeyPreview = True</code>, however that does not seem to work for my application. What am I doing wrong?</p>
  
  <pre><code>Private Sub Main_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
      Me.KeyPreview = True
      AddHandler Me.KeyDown, AddressOf KeyDownsHandler
      AddHandler Me.KeyUp, AddressOf KeyUpHandler
  End Sub
  
  Private Sub KeyUpHandler(ByVal o As Object, ByVal e As KeyEventArgs)
      e.SuppressKeyPress = True
      If e.KeyCode = Keys.F1 Then
          txtMain.AppendText("F1 was pressed!" &amp; Environment.NewLine)
      End If
      txtMain.AppendText( _
          String.Format("'{0}' '{1}' '{2}' '{3}' {4}", e.Modifiers, e.KeyValue, e.KeyData, e.KeyCode, Environment.NewLine))
  End Sub
  
  Private Sub KeyDownHandler(ByVal o As Object, ByVal e As KeyEventArgs)
      e.SuppressKeyPress = True
      txtMain.AppendText( _
          String.Format("'{0}' '{1}' '{2}' '{3}' {4}", e.Modifiers, e.KeyValue, e.KeyData, e.KeyCode, Environment.NewLine))
  End Sub
  </code></pre>