The same principle applies to every other note.
So play along in Gmaj and when you come to the end of a phrase where the melody note is G (say) instead of using a chord from the G set of chords (eg G C Em) use a chord from one those other keys in which G is a scale note (or tension note) like Eflat, (key could be Bflat, Aflat or Eflat) and go off in that other key for a while, then do the same trick to return to G.
This can be done on any note not just the key note.
You could use other chords of course, particularly the minors eg end above on Cmin then you're in any key that has Cmin as a II III or VI.
Bell Bottom Blues works it in the opposite direction by seemingly going to F to G to Am (which is a common progression) but makes the Am and Amaj instead opening up the 'new' key of Amaj.
This is used very often. As always....we just have to practice.
Robbo