Use groups activation/deactivation.
Make several groups - Menu Controls, Code Input, Box Selection etc.
Move all keyboard events for Menu navigation to Menu Controls.
Move all keyboard events for entering code to Code Input.
Move all keyboard events for selecting boxes to Box Selection.
Keep only one group active at a time.
When player is in the menu, enable Menu Controls and disable Code Input and Box Selection groups.
When player is about to input code, enable Code Input, disable other two.
Or you can do this with variables, global or instance. For example:
On keyboard A Pressed
Compare variable currentAction="menu" -> navigate left in the menu
Compare variable currentAction="boxes" -> move to the left box
Compare variable currentAction="code" -> input "A" into the code
[/code:7yjo2vtv]