Learning the 'Circle of 'fifth's & forth's, and being able to write and draw it out, on paper, helped me.
Also recognizing, the concept of 'En-Harmonic', (i.e.) C# is same as Db, ), and writing out the 'Modes' in degrees.
Try to understand the circle of fifths.
For sharp keys, find the scale with increasing number of sharps by going up a perfect 5th.
For flat keys, find the scale with increasing number of flats by going down a perfect 5th.
Then know the order of sharps (FCGD etc.) and flats (BEAD etc.).