A key is a component of a musical instrument, the purpose and function of which depends on the instrument. However, the term is most often used in the context of keyboard instruments, in which case it refers to the exterior part of the instrument that the player physically interacts in the process of sound production.
On instruments equipped with tuning machines such as guitars or mandolins, a key is part of a tuning machine. It is a worm gear with a key shaped end used to turn a cog, which, in turn, is attached to a post which winds the string. The key is used to make pitch adjustments to a string.