Just learn the scales and modes, and then you can position them up or down the fretboard for the different keys.
If you really want to get into music theory, you can learn the circle of fifths and the number of flats and sharps each key has. Then you'll always know what key you're in and what notes you can play.
Personally, I think just learning the scales is easier (I prefer the caged system). Once you do, the circle of fifths and scale tonalities all come naturally, provided you know the notes of the fretboard.
-Christoph