The way is to learn numbers instead of chords. Hence for a C major scale (C, Dm, Em, F, G, Am, we'll leave B dim out at the moment) will be I, ii, iii, IV, V, vi (capital Roman letters for major chords and small letters for minor chords). If you have theory background, it will be easier to understand it.
Then play each piece in EVERY key possible. Start from easy songs. Don't miss the black keys (esp Db major, F# major etc). You'll find that you never had to memorise chords, only the numbers. I've trained my church keyboardists this way since ages past. Still teaching church musicians the same way today. This is because in church, key change is so often and unpredictable. We need to be comfortable to play in any key in any situation (eg. congregation sings in wrong key, or worship leader starts off in wrong key).
What started me on this (ie about 20 years ago) was when I heard one of my friends play 'As the deer" in Db major. I was schooling then. It blewed me away because Db major sounds just right (instead of the usual D). It's the right tonality. So I practiced the song starting from C, then Db, then D, then Eb, F, F# etc and soon found myself addicted to cover every single key (even though it's not singable as it becomes out of range). Then I started doing this for every song I know. After getting used to it, you start add in 7ths, 9ths and 11ths in every single key. I would always spend more time on F# major and B major (I find these 2 more challenging in a live situation). Before long, your fingers "remembers" how each chord feels in each key. Then you know you got it.