The main issue here is that in order to trigger the ‘supplying a missing second noun’ activity, you need to have:
(i) a matching ‘Understand phrase’ that includes only one grammar token for an object (thing)
(ii) a corresponding action that is defined as requiring two things
(iii) have the player type a command that matches the ‘Understand phrase’ in (i) (with only a single object grammar token), but missing the second object required by the action.
In this case, the action ‘unlocking it with’ requires 2 things, but by default there is no Understand phrase matching only one object (the door)- the default solitary Understand phrase being:
Understand "unlock [something] with [something preferably held]" as unlocking it with.
which only matches when the player specifies both the door and the key.
It is not enough in this default situation for the player just to miss out typing the second noun. See WI 18.32 ‘Supplying a missing noun/second noun’.
In the default case, the above is the best-matching ‘Understand phrase’ for what the player typed when the player specifies only the door. Inform does try to guess what is intended as the key- with the help of any applicable ‘does the player mean’ rules but, somewhat counter-intuitively without looking at the ‘supplying a missing second noun’ activity.
However, if we add
Understand "unlock [something]" as unlocking it with
then this becomes the best-matching ‘Understand phrase’ if the player specifies only the door, and now Inform does trigger the ‘supplying a missing second noun’ activity.
So this should work, assuming that you want to have keys in your game at all:
Understand "unlock [something]" as unlocking it with.
A key is a kind of thing.
rule for supplying a missing second noun when unlocking:
if number of keys carried by player is 0:
say "You have no keys.";
otherwise:
[code to choose a key]
If you have no keys in your game, and you want locked things to remain locked, then you can just do
Understand "unlock [something]" as unlocking it with.
rule for supplying a missing second noun when unlocking:
say "You have no keys.";