Place on a door to avoid any unwelcome guests. To craft your key first place the lock on a door and hold E while looking at the Key lock and select 'Create Key', a key will now be added to your crafting queue.
If the key is lost, you cannot make another, so don't forget to make extras and put them in a safe place!