Click here to Skip to main content
15,891,204 members
Articles / Programming Languages / Visual Basic
Article

Pedrams Elite Keylogger

Rate me:
Please Sign up or sign in to vote.
2.97/5 (40 votes)
22 Jun 20054 min read 151.2K   10.6K   52   33
Logs any Keys and/or Blocks Keys/key combinations

Download Source Code
Download Demo Project
Image 1

Note: I intend to make another version, and beside removing bugs and making current code more reliable, I also want to add new features. What features would you like to see in a Keylogger or how could this program be extended? (Please email me at one of the email addresses at the end of the article)

Introduction

This program is capable of capturing any keys at any time. This program can also be customised to preferences. I have created a user interface where you can change options and settings. I have also included a function, where you can block any keys/key combinations pressed.

Using the code

All the keyboard logging/blocking related code is in a module called Keyboard.vb. When you first start the program you might be given an error which says that "Block.txt" is in use or it cannot find "Settings.Set", ignore them and the next time you start the program it should be fixed. In order to see the user interface, you will need to press F12 to exit stealth mode then double-click on the notify icon that appears in the Notification Area (System Tray).

Functions

Below is a list of impotant functions and how they are used

IsHooked - Blocking Keys

(- Public Function IsHooked(ByRef Hookstruct As KBDLLHOOKSTRUCT) As Boolean -)

This function is used to block the key/key combination that has been pressed, to block a key all you have to do is put in 'Return True' :

Public Function IsHooked(ByRef Hookstruct As KBDLLHOOKSTRUCT) As Boolean 
Return True
End Sub

However, this would block any key that is pressed so in order to just block the specified keys you should use Hookstruct.vkcode and the GetAsyncKeyState() function:

Public Function IsHooked(ByRef Hookstruct As KBDLLHOOKSTRUCT) As Boolean 
If Hookstruct.vkcode = 13 Then
Return True
End If
Return False
End Sub

This would block the 'Enter' Key as the keycode for the enter key is 13. Instead of 13, Keys.Enter or VK_ENTER could also be used: Hookstruct.vkcode = 13 > Hookstruct.vkcode = Keys.Enter OR Hookstruct.vkcode = VK_ENTER

To block key combinations the GetAsyncKeyState() function should be used:

Public Function IsHooked(ByRef Hookstruct As KBDLLHOOKSTRUCT) As Boolean 
If GetAsyncKeyState(VK_MENU) and Hookstruct.vkcode = VK_TAB Then
Return True
End If
Return False
End Sub

This would block the key combination ALT + TAB. It first checks too see if the ALT key is down, then it checks too see if the TAB has been pressed. This also means that the Keys ALT and TAB can still be used, but not together.

HookKeyboard & KeyboardCallback - Logging Keys

(- Public Sub HookKeyboard() -)
(- Public Function KeyboardCallback(ByVal Code As Integer, _
      ByVal wParam As Integer, _
      ByRef lParam As KBDLLHOOKSTRUCT) As Integer -)

These two functions are used in logging every key pressed, first HookKeyboard is called from the load event in the main form (Form1.vb) and through a timer, this then 'Hooks' the keyboard and enables the program to log every key pressed. It does this by first retrieving every key pressed before the system does. HookKeyboard then calls KeyboardCallback which determines which key has been pressed. The variable wParam is used to check if any key has been pressed at all:

If wParam = WM_KEYDOWN Then

Once we know that a key has been pressed we have to determine which key it was. This part is easy:

keycode = lParam.vkCode

lParam.vkCode contains the keycode for the key that has been pressed.

In my program, I have used these functions to gather all the keys pressed then write it to a Log File when the user has switched programs:

GetForegroundWindow, GetWindowTextLength, GetWindowText - Logging Keys

(- Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Integer, ByVal lpString As String, ByVal cch As Integer) As Integer -)
(- Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Integer) As Integer -)
(- Private Declare Function GetForegroundWindow Lib "user32" () As Integer -)

In Timer1 I have used these functions to get the program titles that the user has active. The timer builds up a list of Keys (KeysList) that has been pressed, and when the user switches to another program it writes the program title and the keys into the Log file.

If title <> last And last <> "" Then
    writekeys()
End If

It records the windows titles into a variable and checks it agaisnt the new window title, if they are the same the user has still got the same program activated, if they are different the user has switched windows and the keys are written into the Log File.

CreateDefaultSI - Settings

(- Public Function CreateDefaultSI() -)

This is a more simple function which is called if the settings file cannot be found and is corrupt. It deletes the old settings file (if any) then replaces it with a new one with the default settings.

Most functions have not been reviewed in this article and I have just covered the main ones, if you have any questions or need help concerning the code email me at one of the emails listed at the end of this article.

This program was created by Pedram Emrouznejad (p3pedram@hotmail.com, pthree2004@aol.com, pedramscomputer3@aol.com)
Please read the Read Me file (Read Me!!!.txt) (It Explains a lot of stuff)This program is not intended for malicious activities. Use this program at your own risk!
Please retain all credits and give a reference to me and my email when using this code.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionMessage Closed Pin
16-Jul-21 20:10
Ali Trevino16-Jul-21 20:10 
GeneralMy vote of 1 Pin
Nebojsa Janjic9-Feb-12 23:42
Nebojsa Janjic9-Feb-12 23:42 
Questionthis code contains torjan virus Pin
pulkit2829-Dec-11 19:58
pulkit2829-Dec-11 19:58 
GeneralI prefer LightLogger. Pin
minregol10-Nov-10 5:56
minregol10-Nov-10 5:56 
GeneralMy vote of 2 Pin
MARK0248-Mar-10 10:09
MARK0248-Mar-10 10:09 
GeneralSourceCode Pin
sdrolson6-Dec-07 11:11
sdrolson6-Dec-07 11:11 
General[Message Deleted] Pin
Domo9218-Sep-07 9:31
Domo9218-Sep-07 9:31 
GeneralRe: how to remove it? Pin
iSeeGhosts20-Oct-07 14:50
iSeeGhosts20-Oct-07 14:50 
GeneralUgly code Pin
horvardson-gly11-Sep-07 14:59
horvardson-gly11-Sep-07 14:59 
General5 Based on Merit Pin
mntc25-Aug-07 15:17
mntc25-Aug-07 15:17 
GeneralFlamers Pin
MeDammit8119-Jul-07 6:13
MeDammit8119-Jul-07 6:13 
GeneralRe: Flamers Pin
Pedram Emrouznejad19-Jul-07 6:19
Pedram Emrouznejad19-Jul-07 6:19 
GeneralRe: Flamers Pin
MeDammit8119-Jul-07 6:57
MeDammit8119-Jul-07 6:57 
GeneralWOW is Right Pin
T.D.Brown10-Oct-06 5:38
T.D.Brown10-Oct-06 5:38 
Generalwow! Pin
kachie12-May-06 12:17
kachie12-May-06 12:17 
GeneralRe: wow! Pin
Pedram Emrouznejad14-May-06 11:52
Pedram Emrouznejad14-May-06 11:52 
QuestionHow dumb can a single person be Pin
mav.northwind22-Jun-05 20:22
mav.northwind22-Jun-05 20:22 
AnswerRe: How dumb can a single person be Pin
tom_dx23-Jun-05 6:31
tom_dx23-Jun-05 6:31 
GeneralRe: How dumb can a single person be Pin
mav.northwind23-Jun-05 7:34
mav.northwind23-Jun-05 7:34 
AnswerRe: How dumb can a single person be Pin
Pedram Emrouznejad24-Jun-05 7:32
Pedram Emrouznejad24-Jun-05 7:32 
GeneralRe: How dumb can a single person be Pin
mav.northwind24-Jun-05 19:23
mav.northwind24-Jun-05 19:23 
GeneralRe: How dumb can a single person be Pin
Pedram Emrouznejad24-Jun-05 22:55
Pedram Emrouznejad24-Jun-05 22:55 
GeneralRe: How dumb can a single person be Pin
mav.northwind25-Jun-05 2:00
mav.northwind25-Jun-05 2:00 
GeneralRe: How dumb can a single person be Pin
Pedram Emrouznejad25-Jun-05 8:23
Pedram Emrouznejad25-Jun-05 8:23 
GeneralRe: How dumb can a single person be Pin
tom_dx26-Jun-05 12:15
tom_dx26-Jun-05 12:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.