CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Guest

    How to trap key press events ( Key Strokes)

    Hi Friend ,

    I would like to develop an exe in VB which helps me to record each key press event .

    -ie- I want to develop a keylogger

    The exe should tell me which key has been pressed .

    Hoping to get a reply soon .

    Mohit.


  2. #2
    Join Date
    Feb 2000
    Location
    garden grove, california
    Posts
    64

    Re: How to trap key press events ( Key Strokes)

    ' make a timer and interval to 1
    Private Sub Timer1_Timer()
    If GetAsyncKeyState(vbKeyControl) <> 0 And GetAsyncKeyState(vbKeyX) <> 0 Then

    msgbox "Control and X was pressed!!!!!!"
    End If
    End Sub
    ' oh yeah, put this in the forms declarations

    Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer



  3. #3
    Guest

    Solution: How to trap key press events ( Key Strokes)

    You can trap what key was pressed using "KeyPress Event".
    KeyPress Event takes ASCII value of the key pressed as parameter.
    You can use the ASCII value to find out which key was pressed.
    In VB's HELP,You can get the ASCII value of each and every character on the KeyBoard.This will help you to make your KeyLogger App.



  4. #4
    Join Date
    May 1999
    Location
    Omika, Japan
    Posts
    729

    Re: How to trap key press events ( Key Strokes)

    GetAsyncKeyState Works. But it is meant to ckeck only ONE key state.

    The ideal thing for your requirement is to write a keyboard hook procedure. Writing it in VB really requires a very good knowledge over API. because if you mess up somewhere, you will stop other apps from responding too.

    You have to create a hook procedure which follows certain rules. In the sense that it calls the next hook with CallNextHook ?! (or some such thing)

    Install it using SetWindowsHookEx.
    Look into MSDN for this fn, and i think there should be one example.


    RK

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

Featured