I would like to know what criteria composers use when choosing the key of a song. In the case of music composed for orchestra or, in general, for instruments with limited tessitura or tuned in a certain key, I understand that it may be more convenient to choose one key than another. In the piano, however, even though there are no such limitations, great composers often chose more complicated keys than necessary. I think that this would be the case, for example, of the third prelude of the first book of Bach's Well-Tempered Clavier, which is in C# major (7 altered notes), and could have been written in the enharmonic key of Db major (5 flats); or just transposing it only one semitone up, in D major, with only 2 alterations.
So, given that a song, when transposed one semitone up or down, is (IMHO) practically indistinguishable from the original for the vast majority of musicians, what is the reason for choosing one key over another?