jQuery has a .keypress method accepting no arguments that simulates a keypress.
$("#target").keypress();
Will trigger a keypress on #target
If you'd like to also select which key was pressed, you can use .trigger. This example is from the docs:
var e = $.Event("keydown", { keyCode: 8});
$("body").trigger(e);
The key code 8 is the key code for backspace in JavaScript.
Let me know how that works for you :)
If you need a function:
function simulateKeyPress(character) {
jQuery.event.trigger({ type : 'keypress', which : character.charCodeAt(0) });
}