add key events and complete borders checking