|This article is a work in progress and may have some incomplete or missing content.|
Key-changing, or modulation, is an incredibly effective tool if used well. When you've been in one key long enough, you should think about moving out into new ground. This is not always necessary or appropriate; some excellent pieces stay in the same key the entire time.
When changing keys, decide how you will approach the shift. Do you want to give warning, or just change gears surprisingly? If you want to give warning, try a leading-tone or dominant of the new key, with perhaps one or two tones changed to fit the old key a little bit. If not, what I like to do is use the melody note I ended on in the old key for the root in the new key, or even just the beginning note of the melody (which will imply a certain key by diatonic structure... unless you want to change your melody modally).
In general, rhythm should change according to the activity level of your piece. Don't have the rhythm change every measure if you're writing something very structured or slow. Of course, you could change something small without much impact. In a piece more spontaneous and wild, you might want to change dramatically every few measures, even throw the melody to the other hand and have the former melody hand take a new rhythm for the accompaniment.
Don't be afraid to write a measure with a simple motive that gets a little lost. A 'gap' measure often can be very useful to create a logical break between melodic sections. Also, for a transition to a new theme, you might think of inserting one measure of a related meter, like 2/4 in 4/4. It should extend what you were doing in the previous 4/4 measure, creating tension that will be resolved when the new theme is heard.
In classical music, modulation often occurs from the tonic key to the subdominant key by lowering the 7th of the scale. For example in C major, adding a B flat to your melody can allow it to modulate into F major. Another common modulation is moving from the tonic key into the dominant key, by raising the 4th note of the scale. In C major, the F becomes an F sharp, which moves the key into G major. The third common modulation in the classical style is moving to the relative minor, for example, C major into A minor (they key with the same key signature).
Romantic music modulates differently. Composers like Schubert, Schumann and Chopin used chromaticism to move through keys by going up or down a semitone, which was an effective way to build suspense. Romantic music also modulates to the key a minor third above, or a major third below. For example, if a piece was in C major, it could modulate up to E flat Major, or down to A flat major, without any notice or preperation, as long as there was a common note (like a C or a G, depending on which way you move).
In Impressionist music, modulation was treated even more freely with modulation being used almost entirely for "color". Modulations were no longer "prepared" or "expected". Parallel chords were an especially common way of modulation in Debussy and Ravel's music. Debussy, in particular, seemed to be fond of unprepared modulations up or down a minor third in a major scale; evidenced famously in Clair de Lune.