Solved

How can I capture a 3 key press combination

Posted on 2004-08-01
7
1,318 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 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:Bob Lamberson
Bob Lamberson 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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 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…
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…

724 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