A key is a property that can be determined for a passage or a composition as a whole. A passage is any part of a composition that, at the moment, we are examining separately from the rest. It may or may not be a complete idea.
Keys are very important for the theory of harmony. Keys are strongly related to scales but they are different concepts. Unlike scales, which can have many different types, a key can only be a major key or a minor key. Like scales, keys have their tonic. For instance, while we can speak about the C major scale, C natural minor scale, C harmonic minor scale and C melodic minor scale, we can only speak about the C major key and C minor key.
In western music, major keys are commonly used for creating a happy mood while minor keys are used to create a sad mood.