Trapping multiple keys

Posted on 2003-02-20
Medium Priority
Last Modified: 2010-05-01
Got a problem - need to trap more than one keys eg: ctrl+enter or ctrl+enter+F1 etc. I am managing but putting in a loop and using the keyDown event. Then I need 2! in case of two key strokes and 3! in case of three key strokes. If this were to be done over all the objects like combo/text box I am using, it becomes pretty painful. Is there an alternative?? Thanx in advance
Question by:anand_007
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
  • 2

Expert Comment

ID: 7993089
i was thinking about hotkeys, but couln't find anything.
a key with a shift key (alt, ctrl, shift) can be trapped at once, but 2 keys with a shift key can't.

but i don't think i't a big problem.
let's say ctrl+enter is the standard combo, that you just have to remember if that combo has been typed, and the addidtional key can be trapped after that.


Accepted Solution

milowe earned 400 total points
ID: 7994517
I think this will solve your problem.  Create a new project with a form.  Add the code below to the form's module.  Run it and press ctrl-enter-F1.  You should see a message box pop up.  Other virtual key constants that you may need can be found in the Windows API viewer.  


Option Explicit

Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
Enum keys
     VK_CONTROL = &H11
     VK_F1 = &H70
     VK_RETURN = &HD
End Enum

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    Dim bCtrl, bF1, bEnter As Boolean
    bCtrl = IsKeyDown(VK_CONTROL)
    bF1 = IsKeyDown(VK_F1)
    bEnter = IsKeyDown(VK_RETURN)
    If bCtrl And bF1 And bEnter Then
        MsgBox "Ctrl-Enter-F1 Pressed"
    End If
End Sub

Function IsKeyDown(key As keys) As Boolean
    IsKeyDown = (GetKeyState(key) < 0)
End Function

Author Comment

ID: 8007214
Thanx a ton for the help!

Author Comment

ID: 8007335
The key codes can be got by doing a search on Keycode Constants in MSDN Library  (I use October 99)

Featured Post

Industry Leaders: 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!

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses
Course of the Month10 days, 4 hours left to enroll

762 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