As someone who majored in music composition, I have a very simple answer. I'd have some sort of idea in my head of what I wanted the music to sound like (or the emotion to evoke). Then I'd fiddly around for quite some time, discarding the things that didn't meet my criteria.
That's sort of a glib answer, but the fact is that no one really knows exactly why certain things evoke certain emotions, even though most composers understand various building block ideas like "odd meters like 5/8 and 7/8 generally evoke intensity and tension" or "brass chorale in a major key sounds triumphant" or "gong crescendo roll is scary". And of course, even then, we could find counter-examples for every one of those things.
Also, all music theory will tell you is why something in some piece of historical music sounded the way people expected it to sound at the time. It will definitely not tell you how to write good original music (though it may be a good guide on how to imitate past composers if that's useful for what you're trying to do).
Can you recommend any books that teach these sorts of general rules, or the emotive feeling generally associated with different keys and modes?
The way I learned about how composition worked was mostly two things. One, listening to lots of music, ideally with the score in front of me so I could zoom in on some particular bit I really liked. Two, writing music and seeing how it turned out in practice.
You need something like this: https://www.amazon.com/Alfreds-Essentials-Music-Theory-Self-...
It's not something you're going to learn in an afternoon or a weekend, it's hard work and Beethoven was still working on it at the end of his life.
Last month I spent an evening analyzing and discussing a passage of Rachmaninoff, trying to understand how he knew how to write a certain sequence.
I haven't yet come across anything that is a good gentle intro. Most resources that approach music and math make the mistake of treating music theory like the law, without any rationale for it provided. Music history textbooks typically give a lot more context of how our music theories emerged, but they don't talk about why that might be, based on acoustics, psychoacoustic, and math.
Maybe one day, I'll write the comprehensive intro I wish I'd had.