Keylogger is legal, but you must ensure you are not using it with evil intent, such as stalking someone or intruding on their lives.