PlayKid Posted July 3, 2005 Posted July 3, 2005 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 Quote
jmcilhinney Posted July 4, 2005 Posted July 4, 2005 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 SubNote that you need to check separately for modifier keys (Ctrl, Shift, Alt) using the properties of the KeyEventArgs argument. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.