Solved

Vb.net Hot Key Buttons

Posted on 2007-03-29
11
381 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

911 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