Solved

Vb.net Hot Key Buttons

Posted on 2007-03-29
11
385 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
11 Comments
 
LVL 86

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 86

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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

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

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
 

Author Comment

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

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 86

Expert Comment

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

Glad you got it working.  =)
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

688 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