Merge "Add null check in key event handling."