A keylogger is a piece of softaware that captures all your keystrokes, and sends them to the malicious users.
The comparative advantage that an attacker has of using a keylogger over other techniques is that is gets around all the encryption methods. As we don't use any encrytion when we are typing. We use encryption to store data, and during data transmission.
For instance, here is a link to the keylogger that I built. It captures all the keystrokes, and then sends them to my mail address.Check it out here!!
Besides keystrokes, a keylogger can even have access to your clipborad, audio,search engine queries,instant messaging data,and take snap shots of the screen and send them to the bad guys.
Keyloggers are generally installed when malicious softwares/applications are installed on the computer. A Trojan could install these keyloggers into your computer.
Some of the preventive measures that you can take are: