expression
before I knew it; next thing you know; when I came to; all of a sudden
Fixed expression used to describe a sudden realization or an event that happened without the speaker noticing. Often used at the beginning of a sentence to set up a surprising or unexpected situation.
気がつくと、外は真っ暗になっていた。
Before I knew it, it had become pitch dark outside.
気がつくと、彼は部屋に一人で立っていた。
When he came to, he was standing alone in the room.
気づく is a verb meaning 'to notice' or 'to become aware,' while 気がつくと is a fixed adverbial phrase meaning 'before one realizes' or 'when one comes to.'
From 気がつく (to notice, to become aware) + と (conditional particle), literally 'when one notices.' The phrase has become a set expression for describing sudden realizations or unexpected transitions.