A key of a mechanical piano struck gently and then struck again but much harder this time. In the second case

Yes, the pitch will not change because loudness depends on amplitude and not the pitch. The pitch depends on the frequency of the sound. By hitting it hard it will make its amplitude higher. But the frequency will be same. And the point is to be noted is that the loudness depends on the amplitude not the frequency.

3