Changes to processKeyEvents function