[RESOLVED] Help regarding LL kb hooks and keybd_event.-VBForums
Results 1 to 3 of 3

Thread: [RESOLVED] Help regarding LL kb hooks and keybd_event.

  1. #1

    Thread Starter
    Join Date
    Nov 2008

    Resolved [RESOLVED] Help regarding LL kb hooks and keybd_event.

    Hey there.
    Sometime ago I developed a small app for myself that would send a series of key strokes to another app based on the contents of a file. It worked very well. Sadly today I am unable to recreate this app. for some unknown reason.
    I have a very basic hook app which monitors for a particular key press combo. ie ALT & F12 (Whatever). This then opens a file that contains the keys I want to pass to another app. The purpose is to make life easy for myself by automation of repetitive tasks.
    My problem is that when I capture the key combo and it runs the appropriate procedure, I get double entry of what is meant to be passed via the Keybd_Event.
    Im not sure I am calling the proc in the correct place and I dont recall how I overcome this issue years ago.
    The following (shortened) is what I have which does work but its sending twice.
    What do I need to do to recieve '123' in (for example) notepad, or Excel. I dont want '123123'

    Sub SendThis()
    ' This will be dragged from a text file later
        keybd_event VK_1, 0, 0, 0
        keybd_event VK_1, 0, KEYEVENTF_KEYUP, 0 ' 1
        keybd_event VK_2, 0, 0, 0
        keybd_event VK_2, 0, KEYEVENTF_KEYUP, 0 ' 2
        keybd_event VK_3, 0, 0, 0
        keybd_event VK_3, 0, KEYEVENTF_KEYUP, 0 ' 3
    End Sub
    ' I have all the correct Decs in place    
    Public Function LowLevelKeyboardProc(ByVal uCode As Long, ByVal wParam As Long, lParam As KBDLLHOOKSTRUCT) As Long
        If uCode >= 0 Then
            If lParam.vkCode = VK_END Then 'simplicity till the details are sorted.
                LowLevelKeyboardProc = 1
                Exit Function
            End If
        End If
        LowLevelKeyboardProc = CallNextHookEx(hHook, uCode, wParam, lParam)
    End Function

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Beside Waldo

    Re: Help regarding LL kb hooks and keybd_event.

    This may be a simple problem to solve. You are probably receiving the key twice, once as a DOWN and again as an UP. You'll want to test the wParam parameter. It should contain a WM_KEYUP, WM_SYSKEYUP, WM_KEYDOWN, WM_SYSKEYDOWN value.

    If you only want to send it once, no matter how long user holds key combo down. Send it when you receive the WM_KEYUP/WM_SYSKEYUP wParam. Otherwise, send it after the WM_KEYDOWN/WM_SYSKEYDOWN wParam
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online

    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3

    Thread Starter
    Join Date
    Nov 2008

    Re: Help regarding LL kb hooks and keybd_event.

    Its what I wanted. Now for some refining. Thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts


Click Here to Expand Forum to Full Width