Every time a key is pressed a code is generated. A Keylogger, hardware or software, intercepts those keystrokes before sending it to the screen. It can then record and later make sense of it. So for example, if you type email and password one after the other, a hacker can look at the data and make sense of your password.