A man who broke into a home and beat a father senseless with a baseball bat for five minutes after finding out the man was sleeping with his ex also threatened his children, a court has heard.