Added mouse handling and fixed keyboard buffering.