no sooner than; as soon as; immediately after
Used after the past tense of a verb to express that something happened right after another action, often with a sense of surprise or unexpectedness.
No sooner had I left the house than it suddenly started raining.
at the thought of; when I think about
Expresses a feeling or reaction that arises just by thinking about something. Often used with emotions like sadness, worry, or excitement.
彼は帰ってきたかと思うと、またすぐに出かけた。
He came home, but immediately went out again.
My heart aches at the thought of that.
When I think about tomorrow's exam, I can't sleep.
Without か, と思うと is a more straightforward 'when I think that...' and lacks the immediacy or surprise nuance of かと思うと.
Combination of the question particle か, the quotative particle と, the verb 思う (to think), and the conditional/conjunctive particle と. Literally 'when one thinks that...', it developed into a fixed expression for immediate succession or emotional reaction.