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.
そのことを考えるかと思うと、胸が痛む。
My heart aches at the thought of that.
He came home, but immediately went out again.
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.