Keyloggers are programs which logs out the keypress into a file or else stores it inside its memory and are used by hackers to transmit these data to them. I will contain the time, window and every single detail on what you typed and where you typed. On top of it these softwares are super difficult to detect and can get into your system through phishing mails or from some unsafe web sites.
This is made only for educational purpose.
To know more about keyloggers and about the explanation of the code click here