A lot of the movement into keys with more sharps and flats had to do with the development of wind instruments. French Horns, for example, did not always have valves, and waswere limited to certain notes. In the mid-1700s, slides were developed, and in the mid-1800s, valves. This gave it much more versatility. More keys were given to the clarinet which also allowed it to play in more keys. Etc.
The changes in music were not just related to what keys composers wrote in, but also in what instruments were chosen for use in the orchestra. Keyboard and string instruments could play in more keys earlier on, but "full" orchestra music and music written for wind instruments was limited by what the instruments could play.