You can do all of this with events, easily.
For a lock, just make a button that toggles the open and close events to on and off.
[ x ] [0 ] 0 onActivate -> NAMED BRICK (The Door) -> toggleEventsEnabled [0 1]
[ x ] [0 ] 1 onActivate -> Self -> toggleEventsEnabled [2 3]
[ x ] [0 ] 2 onActivate -> Client -> CenterPrint [Door Locked ][3]
[ ] [0 ] 3 onActivate -> Client -> CenterPrint [Door Unlocked][3]
Or something along those lines.
Keypad has quite a few events so I'm not going to go through it.