?
Solved

How do I create a hot key (like Ctrl+C does a copy) and have it execute a Sub?

Posted on 2005-05-10
7
Medium Priority
?
196 Views
Last Modified: 2012-05-05
Friends,

How do I create a hot key (like Ctrl+C does a copy) and have it execute a Sub?

Regards,
Eric
0
Comment
Question by:indy500fan
  • 3
  • 3
7 Comments
 
LVL 96

Assisted Solution

by:Bob Learned
Bob Learned earned 1000 total points
ID: 13969955
If you have a form, trap the keypress by setting the form's KeyPreview = True, and then detect Ctrl+C.  Another way, is to create an Edit | Copy menu with the short-cut key Ctrl+C, and then go from there.

Bob
0
 
LVL 34

Accepted Solution

by:
Brian Crowe earned 1000 total points
ID: 13970038
Here's an example with the form's keypreview property set to true

Private Sub frmOrderSearch_KeyDown(ByVal sender As Object, _
         ByVal e As System.Windows.Forms.KeyEventArgs) _
         Handles MyBase.KeyDown

        Select Case e.KeyCode
            Case Keys.Enter
                Search()
            Case Keys.Escape
                Me.Close()
            Case Keys.P
                If e.Modifiers = Keys.Control Then
                    PrintCurrent()
                    e.Handled = True
                End If
            Case Keys.V
                If e.Modifiers = Keys.Control Then
                    View()
                    e.Handled = True
                End If
            Case Keys.X
                If e.Modifiers = Keys.Control Then
                    Void()
                    e.Handled = True
                End If
        End Select
    End Sub
0
 

Author Comment

by:indy500fan
ID: 13970483
You guys are great!  Now who do I give the points to?  Bob, you gave me an answer first, but BriCrowe gave me another example.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 96

Expert Comment

by:Bob Learned
ID: 13970496
I was trying to teach you to fish, and BriCrowe gave you a fish.  Both are valid, so a split is OK with me.

Bob
0
 

Author Comment

by:indy500fan
ID: 13970542
:) Bob, now if only you can teach me about TCP communications.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 13970555
Do you have a question URL?

Bob
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses
Course of the Month14 days, 8 hours left to enroll

839 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