re-factor method processKeyEvent