I had the same difficulty when I returned to the piano in my adult years but I eventually overcame it, after enduring daily practice of scales, arpeggios, as well as sight-reading easy pieces in different keys. The others have offered excellent advice but here are some more ideas you could try:
1. Before playing a piece, say in D major, play the scale, common chords, and arpeggios of that key. You'd be surprised at how your hands and fingers seem to adjust naturally to the notes.
2. Transpose C major pieces to "nearby" keys. For example, try playing the Hanon exercises in C minor or even C# minor. The notes would look the same but some will fall on the black keys.
3. Copy any short piece by hand onto a blank music sheet and transpose it in all keys, major and minor. This is tedious but you will "love" accidentals after doing a dozen or so.
As others have pointed out: scales, scales, scales. Good luck!