Added function to programatically generate a KeyPress event