Originally Posted by goodatcrashing
Not quite, the key has a rolling code, so the code only works once.
Indeed. The code changes every time as you say. So in non-keyless type of lock, the key sends a code (which changes every time) when you press the key fob button and then the car verifies said code. Therefore, it's not possible to capture the code and use it later (which used the be the case on early remote locking).
But from what Takamo says another device can initiate the sending of the code, and only the car knows what code to send. So I assume it's initially a simple frequency to activate the challenge/response exchange of codes.