How does a keylogger work?

Can you answer this question?