Define and dispatch key events