Results 1 to 8 of 8

Thread: Capture keyboard input

  1. #1

    Thread Starter
    Hyperactive Member vbud's Avatar
    Join Date
    Jan 2002
    Location
    Mru 20 17S, 57 33E Goal: Get out of the BOX Status: In The Shadows!!! Target Posts: 3,000,000,000
    Posts
    378

    Cool Capture keyboard input

    Hello there, I need to make a program that can capture keyboard input from any window that has input focus. Anybody can help me out with some piece of code?

  2. #2
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    you'll need to look at the GetAsyncKeyState
    Try the API guide download at www.allapi.net for a sample of this one

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  3. #3
    Frenzied Member MerrionComputin's Avatar
    Join Date
    Apr 2001
    Location
    Dublin, Ireland
    Posts
    1,616
    #If you are using WinNT4, Win2K or WinXP you can install a WH_KEYBOARD_LL hook that will receive keyboard event notifications for every keypress regardless of whether your application has focus or not...

    To do this with the EventVB.dll :

    Code:
     '\\ In form declarations...
    Dim WithEvents vbLink As EventVB.APIFunctions
    Dim WithEvents vbKddHook As EventVB.EnumHandler
    
    
     [COLOR=green]'\\ Start hook when form loads [COLOR]
    Private Sub Form_Load()
    
    Set vbLink = New APIFunctions
    
    Set vbKbdHook = vbLink.EventhandlerLink
    vbKbdHook.StartHook WH_KEYBOARD_LL, vbLink.ModuleHandle, 0
    
    End Sub
    
    
     [COLOR=green]'\\ Stop hook when form unloads [COLOR]
    Private Sub Form_Unload()
       vbKbdHook.StopHook WH_KEYBOARD_LL
    End Sub
    
     [COLOR=green]'\\ Process keyboard events [COLOR]
    Private Sub vbKbdHook_HOOKPROCKEYBOARDLL(Action As EventVB.enHookCode, ByVal KeyState As Long, ByVal KeyStrokeInfo As EventVB.ApiKBDLLHOOKSTRUCT, lMsgRet As Long)
    
    With KeyStrokeInfo
        If .KeyReleased Then
            Debug.Print .KeyNameText & " released"
        End If
    End With
    
    End Sub
    HTH,
    Duncan
    ----8<---------------------------------------
    NEW - The .NET printer queue monitor component
    ----8<---------------------------------------
    Now with Examples of use

  4. #4
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    Further to the PM I just got...
    Goto http://www.allapi.net/agnet/aanreg.php and download the program.
    Search for "GetAsyncKeyState" down the left hand side and the right side will have some code under the Examples tab. Shove this into a new form & module & run it.

    Follow the on screen instructions and this is basically the same as you're trying. By then changing this line in the sample :
    Code:
    MsgBox sSave
    to
    Code:
    Clipboard.Clear
    Clipboard.SetText sSave
    this will copy the text to the clipboard.

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  5. #5

    Thread Starter
    Hyperactive Member vbud's Avatar
    Join Date
    Jan 2002
    Location
    Mru 20 17S, 57 33E Goal: Get out of the BOX Status: In The Shadows!!! Target Posts: 3,000,000,000
    Posts
    378

    Thumbs up

    Thanx guys for the reply.
    Thanx alex_read i got the sample code from allapi. That really helped me out!!!

  6. #6

    Thread Starter
    Hyperactive Member vbud's Avatar
    Join Date
    Jan 2002
    Location
    Mru 20 17S, 57 33E Goal: Get out of the BOX Status: In The Shadows!!! Target Posts: 3,000,000,000
    Posts
    378

    Thumbs up

    Thanx guys for the reply.
    Thanx alex_read i got the sample code from allapi. That really helped me out!!!

    cheeers

    vbud

  7. #7
    Hyperactive Member MetallicaD's Avatar
    Join Date
    Feb 2001
    Location
    Tallahassee, FL
    Posts
    488
    Watch out there, when you start using those keyboard hooks, some antivirus programs (specifically McAfee) will pick up your code as a virus.. a keystroke logger..

    -mcd
    [vbcode]
    '*****************************
    MsgBox "MCD :: [email protected]", vbInformation + vbOKOnly, "User"
    '*****************************
    [/vbcode]

  8. #8

    Thread Starter
    Hyperactive Member vbud's Avatar
    Join Date
    Jan 2002
    Location
    Mru 20 17S, 57 33E Goal: Get out of the BOX Status: In The Shadows!!! Target Posts: 3,000,000,000
    Posts
    378
    Thanx MetallicaD i`ll try to keep that in mind!!!
    >!v!<
    Free your mind, stop thinking
    http://inspirone.blogspot.com

    Please rate this post if it helped you

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