Is there any way to replay a keyboard event to a textfield and also make the receiving input field add that character to its text? Because I can't make it to work.
Let's say I press a
on the keyboard and a global handler on body captures it. Now I want to replay it to a given textfield. So if the user presses a
on the keyboard it would show up inside the textfield, solely based on the event. The event pops up at the input, but the character is not inputted. Is this possible? I want to avoid manipulating the input text with .val()
;
Example:
$('body').on('keyup', eKeyUp);
$('#mancineni').on('keyup', eKeyUpINPUT);
function eKeyUp(e)
{
$e = $.Event('keyup');
$e.which = e.which;
$e.charCode = e.charCode;
$e.keyCode = e.keyCode;
$e.shiftKey = e.shiftKey;
$e.key = e.key;
$('#mancineni').trigger($e);
//$('#mancineni').focus();
}
function eKeyUpINPUT(e)
{
console.log('g', e)
e.stopPropagation();
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="text" id="mancineni">