I want to ask about what emotion motivated someone to do something. Can the phrase "what were you thinking when you..." be used for this? It seems kind of unnatural to ask, "what were you feeling when you..." I googled "what were you feeling to" and didn't come up with anything. When I googled "what were you thinking to" I came up with lots of stuff, but they seemed to be all inquiries about the logic that drove them to do something, not the emotion that drove them to do it.
If "what were you thinking to" and "what were you feeling to" can't be used, then what phrase can? The nearest thing I can think of is, "what made you do it," but that doesn't seem to be quite what I'm looking for.