You can set a variable, for example found_key.

This one you set to 0, and change it to 1 when the player finds the key. Now you use if to check whether the player has already found the key. If he/she has, you open the door.

Therefore coding problem.