Vb.net Hot Key Buttons

In vb.net I need to create hot keys for my buttons.  More specifically i need CTRL+F1 through CTRL + F12 to have functions.  is this possible and if so how?
dprundleAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mike TomlinsonMiddle School Assistant TeacherCommented:
Define "hot keys"...

Do you need these to function ONLY when your app is in FOCUS?

...or at anytime, such as when OTHER apps are active?
0
dprundleAuthor Commented:
only when my app is focused.
0
Mike TomlinsonMiddle School Assistant TeacherCommented:
(assuming WinForms here)

Sorry...one more question...what version VB.Net?

VB.Net 2005?
VB.Net 2003 (or below)?
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

dprundleAuthor Commented:
visual studio 2005 vb.net
0
Mike TomlinsonMiddle School Assistant TeacherCommented:
One way...

Public Class Form1

    Private Const WM_KEYDOWN As Integer = &H100

    Protected Overrides Function ProcessKeyPreview(ByRef m As System.Windows.Forms.Message) As Boolean
        Select Case m.Msg
            Case WM_KEYDOWN
                If My.Computer.Keyboard.CtrlKeyDown AndAlso (Not My.Computer.Keyboard.AltKeyDown) Then
                    Select Case m.WParam.ToInt32
                        Case Keys.F1
                            Debug.Print("Ctrl F1")
                            Return True

                        Case Keys.F2
                            Debug.Print("Ctrl F2")
                            Return True

                        Case Keys.F3
                            Debug.Print("Ctrl F3")
                            Return True

                        ' etc...

                    End Select
                End If

        End Select
    End Function

End Class
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dprundleAuthor Commented:
Where do I put this at?
0
Mike TomlinsonMiddle School Assistant TeacherCommented:
You put this code INSIDE whatever form you want it on:

    Private Const WM_KEYDOWN As Integer = &H100

    Protected Overrides Function ProcessKeyPreview(ByRef m As System.Windows.Forms.Message) As Boolean
        Select Case m.Msg
            Case WM_KEYDOWN
                If My.Computer.Keyboard.CtrlKeyDown AndAlso (Not My.Computer.Keyboard.AltKeyDown) Then
                    Select Case m.WParam.ToInt32
                        Case Keys.F1
                            Debug.Print("Ctrl F1")
                            Return True

                        Case Keys.F2
                            Debug.Print("Ctrl F2")
                            Return True

                        Case Keys.F3
                            Debug.Print("Ctrl F3")
                            Return True

                        ' etc...

                    End Select
                End If

        End Select
    End Function

So it goes INBETWEEN these two lines in the IDE:

    Public Class Form1

    End Class

Where "Form1" is the name of your form...
0
dprundleAuthor Commented:
Thanks,  I was just wondering if I had to do anything special (like create a new class) to get it to work. I'll try it out now.
0
dprundleAuthor Commented:
this isn't working.. i even replaced debug.print with msgbox("Im working") and its not doing anything.
0
dprundleAuthor Commented:
wow i'm an idiot. i didn't have flock on.  Thanks for your help.
0
Mike TomlinsonMiddle School Assistant TeacherCommented:
"flock"?...

Glad you got it working.  =)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Editors IDEs

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.