〜たとたん(に)
the moment, just as
Verb た-form + とたん(に)
Sign up free to review this point on a spaced schedule.
とたん says the second thing happened the instant the first one did: 家を出たとたん、雨が降り出した, "the moment I left the house, it started raining".
It always follows the た-form, and the second part is usually something sudden or unexpected, outside the speaker's control: a feeling, a reaction, an event. That's why it can't be used for your own planned actions: not 家に帰ったとたん、宿題をした.
とたんに means the same; the に is optional.
Compare すぐ, "straight away", which doesn't carry the surprise, and と同時に, which is more neutral and can follow the dictionary form.
Examples
家を出たとたん、雨が降り出した。
The moment I left the house, it started raining.
立ち上がったとたん、めまいがした。
The moment I stood up, I felt dizzy.
ベッドに入ったとたん、寝てしまった。
I fell asleep the moment I got into bed.
窓を開けたとたん、冷たい風が入ってきた。
The moment I opened the window, a cold wind blew in.
彼は私の顔を見たとたんに、笑い出した。
The instant he saw my face, he burst out laughing.