Ask a Maestro: Why do we have Keys?

AKA how does a composer choose the key to write his or her piece in?