Automatically grab screen shots from flip

Hi everyone, how difficult would it be to configure a preference that automatically takes a screenshot at each Flip? This would be very useful for generating images to use in a method writeup, without having the code littered with GetImage calls.

It seems like something that should be simple to implement, but I don't have any experience with mex files. Where would one start?