Musical Instruments Digital Interface (MIDI) in Audio Toolbox can be used to create, send & receive MIDI messages. So it can be used to set up a piano with MATLAB. And for setting up the webcam using a support package, refer the following link.
For clicking pictures with a keypress, callback functions can be implemented along with a keypress event to simulate this scenario.