Keystroke logging / keyloggerThis type of program records every keystroke that you make. Mostly keyloggers are pieces of malicious software, but not necessarily so: it can also be that for certain reason you may want to download such a program yourself. We can call the utility that remembers what you type into a online form a keylogger too: they are very familiar in almost every common browser and fill in the forms for you the next time that you encounter one. Other types of keyloggers take screenshots and a third type stores everything in a file or sends it unknowingly to an attacker who wants to find out what your passwords are, your social number etc.
Often these programs come together with other downloadable files, hiding in the background, sometimes you can "catch" one just by browsing an infected or malicious website.
Keyloggers also can come in hardware-form: think f.e. of a skimmed ATM: the main goal of the skimmer is to record everything you type into the bank-machine, or a camera located in a spot where it can record everything somebody types on any form of keyboard.
The legal use of keyloggers comes down to user consent: f.e. parental control or monitoring your device while you are away are legal forms of using keyloggers.