Creating a Simple Key Logger in C#

Written By: Dragos Nicholas

- 13 Sep 2008 -
















Description: Learn how to program a simple key logger with the help of C# and the .NET Framework. And that's not all, it saves the keystrokes into a file and periodically sends the file as an email attachment.

  1. Creating the Project
  2. Running the Key Logger at Windows Startup
  3. You've Got Mail
  4. Intercepting Keystrokes
  5. The HookCallback Method
  6. API Methods
  7. Possible Errors

Intro

In the following minutes, you will learn how to program a simple key logger with the help of C# and the .NET Framework. And that's not all, this key logger is "smart". It saves the keystrokes into a file (you choose where) and at a designated interval, it will send the file as an attachment in a mail on your Gmail address.

What is a key logger? Well, keystroke logging (often called key logging) is a method of capturing and recording user keystrokes. Key logging can be useful to determine sources of errors in computer systems, to study how users interact and access with systems, and is sometimes used to measure employee productivity on certain clerical tasks. Such systems are also highly useful for law enforcement and espionage - for instance, providing a means to obtain passwords or encryption keys and thus bypassing other security measures.

Enough talk, let's get to work.

Creating the Project

First, open Visual Studio. Go to File? New ? Project… and select "Windows", "Console Application". Name it "Keylogger" or whatever you want. Check "Create directory for solution" if it's not already checked. If you're ready, press OK. Visual Studio will create the code necessary for your project. Now, please click File? Save all to save your project files.

Go to "Project" on the menu strip and click "Keylogger Properties…". This application doesn't require a User Interface. The reason is obvious :). On the "Application" tab, select "Windows Application" as the output type. Do this to hide the console while the application is running. Another important thing is to go to the "Project" tab in Visual Studio, select "Add reference…" the click "System.Windows.Forms" reference. We will need it for the keystrokes.

Article written by Nicholas, webmaster of Freeware Software Downloads.

Next >>