Problem regarding the capture of screenshots while exploit is in progress

Can anyone share an approach on how to automate the taking of screenshots while the exploit is in progress? I am talking about the exploitation of vulnerabilities by the Metasploit framework. Thanks in advance.