कुंजी प्रेस ईवेंट का अनुकरण करने के लिए, ईवेंट हैंडलर का उपयोग करें। आप एक कुंजी प्रेस ईवेंट का अनुकरण करने के लिए निम्न कोड चलाने का प्रयास कर सकते हैं
उदाहरण
लाइव डेमो
<html>
<head>
<script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js">
</script>
<script>
jQuery(document).ready(function($) {
$('body').keypress(function(e) {
alert(String.fromCharCode(e.which));
});
});
jQuery.fn.simulateKeyPress = function(character) {
jQuery(this).trigger({
type: 'keypress',
which: character.charCodeAt(0)
});
};
setTimeout(function() {
$('body').simulateKeyPress('z');
}, 2000);
</script>
</head>
<body>
<p>press any key</p>
</body>
</html>