Because you mention depth-first(-search) (DFS) I assume, your maze is a graph where nodes represent rooms. The nodes are connected if there is an unlocked door between rooms. The graph may be cyclic.
You have a start room and may be looking for something in the maze. So you enter a room, check every door, whether it is unlocked or you have key that fits and open every possible door. You may find a key. Then you add that key to your keyring and restart in the start room.
Formally (adapted from de:wikipedia; see also en.wikipedia):
DFS(node, goal)
{
if (node == goal)
return node;
else if (node.contains(newKey))
{
addToKeyRing(newKey);
resetMaze();
DFS(startRoom, goal);
} else
{
stack := expand (node) // all unvisited rooms that can be entered pushed on stack
while (stack is not empty)
{
node' := pop(stack);
DFS(node', goal);
}
}
}