I had just arrived at the hotel when I remembered that I had left my keys in the office.
Here, when means "and it was the moment that~", so it means,
I had just arrived at the hotel and it was the moment that I remembered that I had left my keys in the office.
But how about this?
I had gotten used to coffee when I was in Brazil.
Here, when means during, which is just a time marker letting us know when the main clause happened. So, this means,
I had gotten used to coffee during in Brazil.
So, here when means two different things:
1: and it was the moment that
2: during(time marker)
So, I'd like to know what's going on here with the conjunction when.