Let's debunk a myth right now: For me, such "inspiration" does not drop from the sky out of nowhere, even if that's how it appears in the moment.
In every case, there's been a lot of work done beforehand. I've done weeks of research. I've come across kernels of ideas or facts that might work well in a story. I dwell on those for days, trying come up with ways to use them in a plot. I might run across a news story or read something in a book that sparks an idea. I think about types of story lines and characters. As best I can, I immerse myself in the location the book will take place to get to know its "personality."
All of this is effort, which is entirely in my head, is major part of my creative process at work.
It helps me uncover dozens of puzzle pieces that then float around. I have to sort through the pieces: which ones belong in the book I'm going to write and which ones don't? I have to look at what's left (often I don't sort them perfectly and have to resort) and then figure out how they fit together into a cohesive picture.
There's a lot of thinking involved, a lot of turning off the car radio and letting my brain ponder as I drive. A lot of daydreaming while I'm making dinner or folding laundry. A lot of jotting down random notes that only I would understand the meaning of.
Then, and only then, while I'm in another one of those moments where I can ponder and still do some brainless activity (like drying my hair) do I have those magical moments where two or three of those puzzle pieces snap together in one quick moment, and I see the vision of what the full picture just might look like.
One bit of irony is that the harder I try to chase the inspiration, the more it eludes me. I have to let it percolate mentally, reaching out with tendrils, coaxing it with whispers to come out of the corner and reveal itself.
Sometimes the process takes longer than others, and that's when I start to panic. What if there isn't a story hiding in the shadows this time? What if I can never coax this one out?
But that's usually the point where the idea, unbeknownst to me, is already maturing somewhere in my head. That's when the puzzle pieces are drawing near one another, getting ready to click together into a new character, a line of dialogue, or a specific scene.
I imagine some writers do have magical moments of inspiration that come out of nowhere, but mine always arrive as the reward for lots of ground work.
A section of Stephen King's On Writing describes writing as uncovering a fossil, uncovering what's already there. I can relate to that. The longer I think and work, the more of the dirt is brushed away. At some point, the bones of the story will be exposed for the first time--but not without all that dirt clearing first.
That's how I work, anyway. I'm sure there are as many ways as there are writers.