[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

How can I capture a 3 key press combination

Posted on 2004-08-01
7
Medium Priority
?
1,324 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

650 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