Handle keyboard and mouse events