make F2 when pressed

Posted on 2008-06-25
Last Modified: 2010-04-23
I have a form , if the user press F2 within the form whenever he is (any control within the form)
if he press f2 to do some thing , like savebuttom.performclick
Question by:Ahmadal_najjar2003
  • 2
LVL 48

Expert Comment

ID: 21870410
Is this what you want ?
    Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown

        If e.KeyCode = Keys.Insert Then


        End If

    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Me.KeyPreview = True

    End Sub

Open in new window

LVL 48

Accepted Solution

jpaulino earned 500 total points
ID: 21870411
Just replace Keys.Insert with Keys.F2
LVL 27

Expert Comment

ID: 21875010
Place this sample in your form and it will capture the keys you want.
  Protected Overrides Function ProcessCmdKey(ByRef msg As Message, ByVal keyData As Keys) As Boolean

        Const WM_KEYDOWN As Integer = &H100

        Const WM_SYSKEYDOWN As Integer = &H104

        If ((msg.Msg = WM_KEYDOWN) Or (msg.Msg = WM_SYSKEYDOWN)) Then

            Select Case (keyData)

                Case Keys.A To Keys.Z                                '<--- Catch the Keys you want

                    MessageBox.Show("You pressed " & ChrW(keyData))  '<--- Then do something

                Case Keys.Right

                    Me.Text = "Right Arrow Captured"

                Case Keys.Left

                    Me.Text = "Left Arrow Captured"

                Case Keys.Down

                    Me.Text = "Down Arrow Captured"

                Case Keys.Up

                    Me.Text = "Up Arrow Captured"

                Case Keys.Tab

                    Me.Text = "Tab Key Captured"

                Case (Keys.Control Or Keys.N)

                    Me.Text = "<CTRL> + N Captured"

                Case (Keys.Alt Or Keys.Z)

                    Me.Text = "<ALT> + Z Captured"

                Case Keys.NumPad0

                    Me.Text = "Num Pad '0' Captured"

                Case Keys.Delete

                    MessageBox.Show("Delete Captured")

                Case Keys.NumLock

            End Select

        End If

        Return MyBase.ProcessCmdKey(msg, keyData)

    End Function

Open in new window


Author Closing Comment

ID: 31470792
Thank alot

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String ( Literal, only instead of starting and ending with w…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now