"instrument for opening locks," Middle English keie, from Old English cæg "metal piece that works a lock, key" literal and figurative ("solution, explanation, one who or that which opens the way or explains"), a word of unknown origin, abnormal evolution, and no sure cognates other than Old Frisian kei.
Perhaps it is related to Middle Low German keie "lance, spear" on notion of "tool to cleave with," from Proto-Germanic *ki- "to cleave, split" (cognates: German Keil "wedge," Gothic us-kijans "come forth," said of seed sprouts, keinan "to germinate"). But Liberman writes, "The original meaning of *kaig-jo- was presumably '*pin with a twisted end.' Words with the root *kai- followed by a consonant meaning 'crooked, bent; twisted' are common only in the North Germanic languages." Compare also Sanskrit kuncika- "key," from kunc- "make crooked."
Modern pronunciation is a northern variant predominating from c. 1700; earlier and in Middle English it often was pronounced "kay." Meaning "that which holds together other parts" is from 1520s. Meaning "explanation of a solution" (to a set problem, code, etc.) is from c.1600.
The musical sense originally was "tone, note" (mid-15c.). In music theory, the sense developed 17c. to "sum of the melodic and harmonic relationships in the tones of a scale," also "melodic and harmonic relationships centering on a given tone." Probably this is based on a translation of Latin clavis "key," used by Guido for "lowest tone of a scale," or French clef (see clef; also see keynote). Sense of "mechanism on a musical instrument operated by the player's fingers" is from c. 1500, probably also suggested by uses of clavis. OED says this use "appears to be confined to Eng[lish]." First of organs and pianos, by 1765 of wind instruments; transferred to telegraphy by 1837 and later to typewriters (1876).
hole n.
Old English hol (adj.) "hollow, concave;" as a noun, "hollow place; cave; orifice; perforation," from Proto-Germanic *hulan (source also of Old Saxon, Old Frisian, Old High German hol, Middle Dutch hool, Old Norse holr, German hohl "hollow," Gothic us-hulon "to hollow out"), from PIE root *kel- (1) "to cover, conceal, save." As an adjective, it has been displaced by hollow, which in Old English was only a noun, meaning "excavated habitation of certain wild animals."
As a contemptuous word for "small dingy lodging or abode" it is attested from 1610s. Meaning "a fix, scrape, mess" is from 1760. Obscene slang use for "vulva" is implied from mid-14c. Golfing hole-in-one is from 1914; as a verbal phrase from 1913. To need (something) like a hole in the head, applied to something useless or detrimental, first recorded 1944 in entertainment publications, probably a translation of a Yiddish expression such as ich darf es vi a loch in kop.