OK, so I was asking myself this while thinking about standard notation. If you start by writing a melody that has a lot of chromatic notes or is generally all over the place, how do you know what key you are in? I presume this has to do with a “home” or tonic note but wanted to ask.
Generally, being “in key” refers to picking notes that fit within a diatonic scale, such as C major - A minor. It can be sometimes difficult to figure out your key if you haven’t prescribed one from the get go. So what do you do? First thing I always think about is the “center of gravity” - of all the notes, which note sounds like the center? Could you start and end on that note and feel satisfied. If so, chances are it is your tonal center and you can begin shaping your key around that. Is it major, or is it minor? Happy or sad? Once you figure that out, you are one step closer. This may not help with something that changes key frequently (jazz) or something that has a purposely obscured key (atonal etc) but for MOST applications (meaning 99 percent of what you hear or compose) this will get you there.
It is a skill! It’s one thing I work on with my students that are interested in transcription or composition. You generally don’t just understand how to do it and get it going but rather you have to practice doing this all the time. As a guitar teacher, working with students keeps my key ear generally warm.
Referring directly to your chromatic notes example - are the notes that are chromatic integral to the piece? Or are they passing tones? Does the HARMONY feel chromatic too? Like the bass notes you would put underneath (even if you don’t know what they are)? See if you can get questions that provide binary “yes no” answers as opposed to trying to do everything at once, which is what figuring out key is akin to.
TLDR version: Find a note that sounds like home.