Solved

Vb.net Hot Key Buttons

Posted on 2007-03-29
11
382 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
ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

 

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
 

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

770 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