Here's a quote from the question with the question's incorrect assumption in bold:
Say, I want to write a track in the key of D. So I have the notes D,E,F#,G,A,B & C#. I cannot use any other notes than these.
Key is mostly about the home note. The home note is D. Secondarily, it is about the home chord, specifically, whether the home chord has a major or minor third (in the case of D, whether it includes an F♯ or F♮).
Beyond that, it's a bit vague and maybe even statistical. Most pieces in D major will mostly use the seven scale notes you listed. But that's not the primary condition that causes a piece to be in D major, nor even a necessary one.
If you want to understand key from a historical point of view, start with some music from the early 1600s. Simpler tunes, especially, stay in the diatonic scale. But sometimes you'll have a more complicated tune. The first phrase starts on D but ends on A, then the second phrase returns to D. Toward the end of that phrase, there may be a G♯, which you might think of as having been "borrowed" from the key of A. That doesn't stop the overall key of the piece from being D, however.
These sorts of excursions into other tonal areas became more common and more adventurous over the next few centuries. Other reasons for introducing chromatic notes also arose. For example, where there is a whole step between notes of the scale, you might just fill in that interval by adding the half step between them. That is, a part with the notes A, G, F♯ might turn into A, A♭, G, F♯.
Both of these practices are sometimes said to be "colorful," in that they supposedly add interest or variety to the music, and indeed "chromatic" comes from a Greek word meaning "color."
But THE CHROMATIC SCALE suggests the usage of all the 12 notes (all white and black keys). Which means I really can use notes out of key?
Yes!
I really don't understand what is going on here! Please explain with simplicity like you would teach a 12 year old.
A piece that is in D major will have a home pitch of D and will prefer to use the notes of the D major scale, but may use other notes for any of several reasons, perhaps because the key center moves temporarily to another note or perhaps just for "color."