Keylogger is a computer utility used for "logging" keystrokes made by the user. The compiled program is usually placed in the systems folder and will run automatically when the user logs in. Most of these keyloggers are compiled with either Visual Basic or with C++.
This is a good method for spying someone's password or activities.
In Visual Basic, the code usually has a few API calls that record keystrokes made outside the program. The program then writes the stroke symbol to a public file.
Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
That is the required API call to check if a key is being pressed. To make the program work, most people would check the key state in short intervals.
Create a timer with an interval of 5 or so. In the timer, call the GetKeyState API function with an integer as the parameter. The return value for this will be the key that was held down during the time that the timer code was ran. 0 will be returned if it was "null", meaning nothing was pressed.