In general they're legal, however in case of certain countries I recommend you to check local laws for being totally sure. Also despite the certain countries it really depends on for what purposes you're planning to use this software.
If that's only for your personal needs or as a part of parental control software, than it's definetely ok. Keylogger software is based on recording all keystrokes made on a computer or other gadgets and because of that you can get access to all information connected with certain users (like web searching, e-mail, social media activities and so on). Because of that keylogger
www.refog.com is often used for monitoring children gadgets activities and blocking all possible inappropriate content for them. And yeah, for such parental purposes it's totally legal.
It could be considered illegal only if you use it for adults without their permission, never do that because it's a popular practice of scammers for stealing personal information and you'll get troubles with the law
blogs.findlaw.com/blotter/2017/07/can-i-be-arrested-for-installing-keylogging-software.html .