Handle dialog keypresses appropriately.