?
Solved

How can I capture a 3 key press combination

Posted on 2004-08-01
7
Medium Priority
?
1,319 Views
Last Modified: 2012-05-05
I need to be able to capture Ctl-Alt-F10 for an app that i am writing. now i can get Ctl-Alt, but not the F10 Here is my code:

Public Function LowLevelKeyboardProc(ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Dim fEatKeystroke As Boolean

    If (nCode = HC_ACTION) Then
        If wParam = WM_KEYDOWN Or wParam = WM_SYSKEYDOWN Or wParam = WM_KEYUP Or wParam = WM_SYSKEYUP Then
            CopyMemory p, ByVal lParam, Len(p)
           
            If (VK_F10) And ((GetKeyState(VK_CONTROL) And &H8000) <> 0) And ((p.flags And LLKHF_ALTDOWN) <> 0) Then
                    <Do Stuff>
                    fEatKeystroke = False
                End If
            Else
                fEatKeystroke = _
                ((p.vkCode = VK_TAB) And ((p.flags And LLKHF_ALTDOWN) <> 0)) Or _
                ((p.vkCode = VK_ESCAPE) And ((p.flags And LLKHF_ALTDOWN) <> 0)) Or _
                ((p.vkCode = VK_ESCAPE) And ((GetKeyState(VK_CONTROL) And &H8000) <> 0)) Or _
                (p.vkCode = VK_RWIN) Or _
                (p.vkCode = VK_LWIN) Or _
                (p.vkCode = LLKHF_ALTDOWN) Or _
                (p.vkCode = VK_ESCAPE) Or _
                (p.vkCode = VK_CONTROL And GetKeyState(VK_CONTROL))
            End If
        End If
    End If

   
    If fEatKeystroke Then
        LowLevelKeyboardProc = -1
    Else
        LowLevelKeyboardProc = CallNextHookEx(0, nCode, wParam, ByVal lParam)
    End If
End Function


The line "If (VK_F10) And ((GetKeyState(VK_CONTROL) And &H8000) <> 0) And ((p.flags And LLKHF_ALTDOWN) <> 0) Then" does not work properly all the time.

Can anyone help?
0
Comment
Question by:Silvertree
[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
7 Comments
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11690377
>           If (VK_F10) And ((GetKeyState(VK_CONTROL) And &H8000) <> 0) And ((p.flags And LLKHF_ALTDOWN) <> 0) Then

I think you have to start evaluating:

If (GetKeyState(VK_F10) .... ETCETERA
0
 
LVL 17

Accepted Solution

by:
zzzzzooc earned 1000 total points
ID: 11690528
Try the below. Of course, F10 has to be pressed last.


Public Function LowLevelKeyboardProc(ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Dim kbdllhs As KBDLLHOOKSTRUCT
    If nCode = HC_ACTION Then
        If wParam = WM_KEYDOWN Or wParam = WM_SYSKEYDOWN Then
            Call CopyMemory(kbdllhs, ByVal lParam, Len(kbdllhs))
            'If F10...
            If kbdllhs.vkCode = vbKeyF10 Then
                'If Control...
                If (GetAsyncKeyState(vbKeyControl) And &H8000) <> 0 Then
                    'If Alt...
                    If (GetAsyncKeyState(vbKeyMenu) And &H8000) <> 0 Then
                        MsgBox "Ctrl+Alt+F10"
                    End If
                End If
            End If
        End If
    End If
    LowLevelKeyboardProc = CallNextHookEx(m_hDllKbdHook, nCode, wParam, lParam)
End Function

0
 
LVL 18

Expert Comment

by:JR2003
ID: 11702571
This works:

Start a new project with a blank form and add a timer control to the form
Then paste the following code into the form:

Option Explicit
Private iShiftState As Integer
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal iKey As Long) As Integer

Private Function IsKeyDown(Key As VBRUN.KeyCodeConstants) As Boolean
    If GetAsyncKeyState(Key) = -32767 Then
        IsKeyDown = True
    End If
End Function

Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
    iShiftState = Shift
End Sub

Private Sub Form_Load()
   KeyPreview = True
   Timer1.Interval = 100
End Sub

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    iShiftState = Shift
End Sub

Private Sub Timer1_Timer()
    If (iShiftState And vbCtrlMask) <> 0 Then
        If (iShiftState And vbAltMask) <> 0 Then
            If IsKeyDown(vbKeyF10) Then
                MsgBox "Ctrl+Alt+F10 Pressed"
            End If
       End If
    End If
End Sub
0
 
LVL 12

Assisted Solution

by:Bob Lamberson
Bob Lamberson earned 1000 total points
ID: 11707371
If just want to add code to each form's KeyUp event,

If KeyCode = vbKeyF10 And Shift = 6 Then
   Me.Print "Ctl-Alt-F10 keys pressed"
End If

will get the proper response.



Bob
0
 
LVL 17

Expert Comment

by:zzzzzooc
ID: 12331173
ping
0

Featured Post

Independent Software Vendors: 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 While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month12 days, 7 hours left to enroll

777 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