There are a lot of different types of spyware. As you may have seen many AV's have some kind of Keylogger or webcam protection to stop such spyware attacks. Now to the example that you are mentioning. Every good AV will have signatures for every kind of Malware, this also includes spyware. Sophos Home which I am using for example does have keylogger protection, webcam protection and Malicious Traffic Detection, which blocks outbound and inbound connections to malicious hosts. A Firewall however normally doesn't detect suspicious behaviour of a file and needs you to decide between blocking or allowing it's connection in- or outbound. Be careful tho, because Windows Firewall doesn't block outbound traffic by default, which makes it easier for spyware to contact their own server again and send pontential stolen data from your device without you even noticing it. In the end the best protection from spyware is the same as for every other kind of Malware. Be careful online and only run files from trusted sources. If you are looking for a good firewall that has its focus on preventing spyware attacks, then you might want to go with SpyShelter. It will be very instrusive in the first few days but will become more quiet when all the rules are set for the exisiting software on your device.
Here is the link to SpyShelter: The best anti keylogger program for Windows