The scales of all major and minor keys are diatonic scales. (In a minor key, both the harmonic and melodic forms of the scale are diatonic.) Notes which do not belong to the keys are said to be chromatic. A chromatic scale is a scale made up entirely of semitones: one which includes all the notes (black and white) on the keyboard. 
For about three centuries after 1600 music was generally based on the major and minor scales and not on the chromatic scale. Individual chromatic notes were used, but often as merely special effects (the word “chromatic” means colored) which had no influence upon the key. Sometimes, it is true that their use could bring about a change of key, in which case, the key signature might be changed. During the second half of the 19th century and the early part of the 20th, the use of chromatic notes developed to such an extent that any feeling of tonality (being in the key) was often weakened. In the hands of some composers, it was finally destroyed altogether (in music described as “atonal”), although many others have continued to write tonal music.
When chromatic scales, or parts of them, occur in real music (as distinct from theory books), composers are often not fussy about their notation. Usually, they are written in whatever way feels convenient, bearing in mind the key signature if there is one i.e. using the minimum number of accidentals needed to do the job.

Theorists distinguish between two ways of writing the chromatic scale: the harmonic and the melodic (or arbitrary).

HARMONIC CHROMATIC is the same whether ascending or descending, and whether it occurs in a major or minor key. It includes all the notes of the major and minor scales (both harmonic and melodic), plus the flattened 2nd and sharpened 4th degrees. In practice this always means that every note has to be written twice, except the 5th and, of course, the key-note at the top and bottom.

MELODIC CHROMATIC SCALES are less rigid in their construction: in fact, theorists do not invariably agree exactly how they are formed. What may be said is that they differ in their ascending and descending version, and also according to whether the key is major or minor. Perhaps the simplest way of forming them is to include, first, all the notes of the key (in a minor key, these include the notes of both the harmonic and melodic scales). The additional notes are then provided by sharpening the diatonic notes (when required) in the ascending form, or by flattening them in the descending form.

Some authorities, however, would use the 7th degree twice – e.g. C  (not B ) in the ascending scale in D major; and some would include the sharpened 4th rather than the flattened 5th (G  rather than A  ) in both descending scales. One principle which all would accept is that the same letter must never be used more than twice in succession: thus A – A – A  , for example, would always be wrong.