Hi i wonder if you all can help me please.

I understand about scales and key. I can improvise guitar solos.

My question is tho, once im at this point where i can for instance improvise in any key by starting at the relevent fret and playing a few different scales in the box position. What can i do next, iv tried braching out on the neck and trying new things with some success. I just dont understand how i know what notes are going to be in key and wich ones arent. I seem to be abe to play most notes and they sound right. Plz help me if you can its driving me crazy.
To get real good at improvisation you need a great ear and a good knowledge of harmony. Transcribe music every day. Pick up some harmony books, Mark Levines Jazz Theory is a great book on jazz improvisation and will teach you all the harmony you need to know for jazz and rock.