Solved

How can I capture a 3 key press combination

Posted on 2004-08-01
7
1,303 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
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 250 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:BobLamberson
BobLamberson earned 250 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now