I create a melody by ear, then build off of it.
Currently, I know what notes are in the melody. To find what key it's in, I start looking at all reasonable scales with the same kind notes.
If my notes contain, G, F#, A, B, and Qb, I'll begin by looking at all scales that have G, then all that...