Basically I'm registering a hotkey with RegisterHotKey and then trying to make it send a numpad number with keybd_event. My hotkey and the key I'm sending I cant change this is needed for the program I'm makeing. My best guess at the problem is since Alt+Q and Numpad7 are both happening at the same time there is a conflict with it trying to send Alt+Numpad7. If I add a sleep 1000 in there it works fine. However since this is part of the user interface a 1 second delay is unacceptable.

Please help!!!

My goal is for Alt+Q (not q) to send Numpad7 (not 7) without a delay (sleep).

The code below works great however I need it without the sleep delay.

In Form1
Code:
Option Explicit

Private Sub Form_Load()
Dim Val1 As Boolean
Val1 = RegisterHotKey(Me.hwnd, 0, MOD_ALT, vbKeyQ)
    If Not Val1 Then
        MsgBox "Could not register hotkey.", vbCritical
    End If
    
    Me.Visible = False
    
    glWinRet = SetWindowLong(Me.hwnd, GWL_WNDPROC, AddressOf CallbackMsgs)
End Sub
In a Module
Code:
Option Explicit

Public Declare Sub keybd_event Lib "user32.dll" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Public Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer

Public Declare Function RegisterHotKey Lib "user32" (ByVal hwnd As Long, ByVal ID As Long, ByVal fsModifiers As Long, ByVal vk As Long) As Long
Public Declare Function UnregisterHotKey Lib "user32" (ByVal hwnd As Long, ByVal ID As Long) As Long

Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Public Const WM_HOTKEY = &H312
Public Const GWL_WNDPROC = -4
Public Const KEYEVENTF_KEYUP As Long = &H2
Public Const KEYEVENTF_EXTENDEDKEY As Long = &H1
Public Const VK_MENU = &H12
Public Const VK_NUMPAD7 = &H67
Public Const MOD_ALT = &H1

Public glWinRet As Long


Public Function CallbackMsgs(ByVal wHwnd As Long, ByVal wmsg As Long, ByVal wp_id As Long, ByVal lp_id As Long) As Long
    If wmsg = WM_HOTKEY Then
        Call DoFunctions(wp_id)
        CallbackMsgs = 1
        Exit Function
    End If
    CallbackMsgs = CallWindowProc(glWinRet, wHwnd, wmsg, wp_id, lp_id)
End Function

Public Sub DoFunctions(ByVal vKeyID As Byte)
    If vKeyID = 0 Then
        Debug.Print "Pressed Alt+Q Waiting 1 second"
'Heres the big frickin problem!!!!!
        Sleep 1000
'Help me get rid of the sleep and still make it work!!!!
        Debug.Print "NumPad7"
        keybd_event VK_NUMPAD7, 0, 0, 0
        keybd_event VK_NUMPAD7, 0, KEYEVENTF_KEYUP, 0
    End If
End Sub
This is my first post to this site. I have been working on this problem for 2 weeks. It would mean alot to me if you guys are able to show me how this can be done.

Please Save Me!!!!

-Sinaps