Trigger keypress(keydown) with jQuery
$("#example").click(function() {
$("#search").focus();
var e = jQuery.Event("keydown");
e.keyCode = 50;
$("#search").trigger(e);
});
ref: Definitive way to trigger keypress events with jQuery