implemented keylistener
fixed some bugs in the keylistener