Add handleKeyboard function