Keys are related to scales. Look at a piano keyboard. Each Octave can be divided up into two groups - the group that has two black keys among three white keys (the left-most white key is "C"), and then the group that has three black keys among for white keys. Note that white keys are "natural notes", while the black keys are "sharps" or "flats".
If you start at C and play all of the white keys in order, heading to the right (higher) until you reach the next "C", you've played a scale. But note that by playing the white keys only, you are skipping the black keys - you are skipping some steps. For example, after you play the "C", you play the next white key ("D") but you skipped one step, the C-sharp/D-flat that is the black key in between those two notes. But now suppose you started your scale on the "E" (the next white key after the D). What note should you play next? Its not the next white key (F) - rather, its the next black key (F-sharp / G-flat). Why? Because it is that next black key, and not the next white key, that is two notes away from that first note.
So if you look at the C scale, you can see that the gaps between the notes that comprise that scale are 2-2-1-2-2-2-1. If you start on another note, to play that same scale higher, you have to use some of the black keys to keep the correct gap between the notes.
No matter where you start your scale, you're only playing 8 keys, but where you start determines what those 8 keys are. So a "key" in music basically tells you that if you start on note "x", then the notes you are playing (unless otherwise noted in the music) are the same 8 notes you'd play in the scale starting at that note. So really, a "key" groups 8 notes together that have the proper spacing between them to form a scale.