simulate keyboard pressing

only tested in chrome

JavaScript

window.addEventListener('keypress', function (e) {
    console.log(e);
});

function simulateKeyPress(c, target) {
    var event = document.createEvent("KeyboardEvent");
    event.initKeyboardEvent("keypress", true, true, null, false, false, false, false, c.charCodeAt(0), 0);
    target.dispatchEvent(event);
}
simulateKeyPress('a', document);