locked
Can you create a hot key using a Function Key (F1 - F12)? RRS feed

  • Question

  • To whomever it may concern,

    I am creating a custom notepad program in Visual Basic 2010 Express Edt. and was wondering if it is possible to create a hot key using the Function Keys (F1 - F12). For example, if I press F5 while using my program, It would automatically insert the current date and time, like it does in the regular notepad/wordpad.

    Thank You.

    Friday, December 3, 2010 11:15 PM

Answers

  •   Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
        If e.KeyCode = Keys.F5 Then
          TextBox1.SelectedText = Now.ToShortTimeString & " " & Now.ToShortDateString
        End If
      End Sub
    
    
    • Proposed as answer by Giftzwockel Saturday, December 4, 2010 1:26 PM
    • Marked as answer by Jie BaoModerator Monday, December 13, 2010 1:41 AM
    Friday, December 3, 2010 11:41 PM
  • Hi Gray Wolf 04

    I've found routines similar to that below to be helpful.

    Protected Overrides Function ProcessCmdKey(ByRef msg As Message, ByVal keyData As Keys) As Boolean
        Dim Key_P As String = keyData.ToString
        MsgBox(Key_P)
      End Function
    

    This allows input directly from the keyboard without addressing a TextBox.

    regards Ron

    Saturday, December 4, 2010 1:56 AM

All replies

  •   Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
        If e.KeyCode = Keys.F5 Then
          TextBox1.SelectedText = Now.ToShortTimeString & " " & Now.ToShortDateString
        End If
      End Sub
    
    
    • Proposed as answer by Giftzwockel Saturday, December 4, 2010 1:26 PM
    • Marked as answer by Jie BaoModerator Monday, December 13, 2010 1:41 AM
    Friday, December 3, 2010 11:41 PM
  • Hi Gray Wolf 04

    I've found routines similar to that below to be helpful.

    Protected Overrides Function ProcessCmdKey(ByRef msg As Message, ByVal keyData As Keys) As Boolean
        Dim Key_P As String = keyData.ToString
        MsgBox(Key_P)
      End Function
    

    This allows input directly from the keyboard without addressing a TextBox.

    regards Ron

    Saturday, December 4, 2010 1:56 AM