if you have messed up your controls, then click esc, then settings,then controls and click on jump, then choose a button that is not messed up. Then jump, and place a block. Create them so they look like stairs so you can jump up them to get out(using whatever key you chose to jump) if you dont want your villagers to get out, then destroy the blocks
hope this helps
Purlycat