Emulate Key Events
by Aleksey Karagodnikov
HTML
<input type="button" id="test" value="test">
<input type="text" id="elem1">
JavaScript
function simulateKeyUp(character, element) {
element.trigger({
type: 'keyup',
which: character.charCodeAt(0),
emulation: true
});
}
$('input[type=text]').on('keyup', function(e) {
if (e.emulation) {
console.log(e);
$(this).val($(this).val() + String.fromCharCode(e.which));
}
});
$('input[type=button]').click(function() {
simulateKeyUp('7', $('input[type=text]'));
});