i want to know that what event fired what happens when any key pressed by keyboard on html page. i want to do that with javascript function ie if any html page have a text box with focus and then any key will be pressed it will write in text box. so i want fire same event with javascript function i dont want to change text box value directly.
1 more example for make clear what i wanna say. if i have add a event listener for key press and alert something every time when any key pressdown or up. so if any key will be press by keyboard msg will alert. so i want to do same via javascript function or any thing what is available. and then message should be alert every time when any key press via javascript
I am not sure this is the excat same that you want:
<body>
<input type="text" style="width: 300px;" id="captureInput" />
<script src="https://code.jquery.com/jquery-1.11.1.min.js"></script>
<script>
$(function () {
var captureInput = $('#captureInput');
$(captureInput).focus();
var e = jQuery.Event("keydown");
e.which = 77; // # Some key code value
$(captureInput).val(String.fromCharCode(e.which));
$(captureInput).trigger(e);
});
</script>
</body>
and this is jsfiddle demo
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.