Yes, and many people do it. Particularly songs, which may need transposing into other keys to suit a singer's vocal range.
HOWEVER: this does NOT mean every piece will use only diatonic notes. That means , in key C, exclusively using the white keys. Lots of tunes 'in a key' will use chromatics (notes not included in the standard scale) so, keeping in key C, the black keys can come into play.
So, the answer is yes. You can learn any piece in any one key, using all the notes applicable to that piece, hit the transpose button, and be in whatever key you wish. Be aware that it will only sound good in 12tet, which is the tuning most of us use on keyboards these days. Obviously, with an acoustic piano, there's no transpose button!