Solved

Vb.net Hot Key Buttons

Posted on 2007-03-29
11
379 Views
Last Modified: 2013-11-07
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?
0
Comment
Question by:dprundle
  • 6
  • 5
11 Comments
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 18818637
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
 

Author Comment

by:dprundle
ID: 18818851
only when my app is focused.
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 18818881
(assuming WinForms here)

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

VB.Net 2005?
VB.Net 2003 (or below)?
0
 

Author Comment

by:dprundle
ID: 18818902
visual studio 2005 vb.net
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 18819244
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:dprundle
ID: 18837540
Where do I put this at?
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 18837561
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
 

Author Comment

by:dprundle
ID: 18838950
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
 

Author Comment

by:dprundle
ID: 18839082
this isn't working.. i even replaced debug.print with msgbox("Im working") and its not doing anything.
0
 

Author Comment

by:dprundle
ID: 18839096
wow i'm an idiot. i didn't have flock on.  Thanks for your help.
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 18840241
"flock"?...

Glad you got it working.  =)
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

757 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

18 Experts available now in Live!

Get 1:1 Help Now