Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi all,

 

I am trying to create an application which allows user to enter special keys, such as F1, F2, etc....How may I do that?

 

Thanks

 

PlayKid

Posted

I think I answered this is another forum but in case you are a different person I'll answer it here.

 

If something is important enough to warrant a global hotkey then you should generally have a corresponding menu item. You can then assign a value to the Shortcut property of the MenuItem and you're done.

 

If for some reason you don't have a corresponding menu item, you need to set the form's KeyPreview property to True and then use the KeyDown or KeyUp event handlers (KeyPress won't work for function keys and some others) to test for the keys you want to handle.

    Private Sub Form1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyUp
       If e.KeyCode = Keys.F1 Then
           MessageBox.Show("F1")
       End If
   End Sub

Note that you need to check separately for modifier keys (Ctrl, Shift, Alt) using the properties of the KeyEventArgs argument.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...