~るとき/~たとき({時制|じせい})
When (before/while) doing… / when (after) having done…
N4
V (dictionary form) + とき (action not yet done) / V (た form) + とき (action already done) + main clause
Before とき, the dictionary form (~るとき) means the main clause happens before that action is completed, while the た form (~たとき) means it happens after the action is done. So {日本|にほん}へ{来|く}るとき、{空港|くうこう}でお{土産|みやげ}を{買|か}いました means you bought gifts at the airport back home before leaving, but {日本|にほん}へ{来|き}たとき means after arriving in Japan. The tense of the main clause does not decide the form before とき. At work you often hear 「{帰|かえ}るとき、タイムカードを{押|お}してください」, meaning punch your card before you go home. Learners often use the た form for every past event and say {寝|ね}たとき、{電気|でんき}を{消|け}しました, which sounds like you turned off the light after falling asleep. Compared with ~{前|まえ}に/~たあとで, which simply give order, ~るとき/~たとき point to the moment tied to the action.
Examples
会社を出るとき、「お先に失礼します」と言います。
When I leave the office, I say “Excuse me for leaving first.”
日本に着いたとき、空港から家族に電話しました。
When I arrived in Japan, I called my family from the airport.
工場に入るとき、ヘルメットをかぶってください。
Put on your helmet when you go into the factory.
Exercises
1.寮を とき、部屋の鍵をかけます。
2.国に とき、友だちが空港まで迎えに来てくれました。
3.昨日、寮に とき、「ただいま」と言いました。