I am trying to make a javascript function with jquery that tricks the device using my html page that a keyboard key is being pressed when you click a button on the page, I just have one problem, when I click the button it doesn't work and when i look in the console in Google Chrome it says Uncaught TypeError: undefined is not a function
,
here is the javascript:
function simulateKeyPress(keycode) {
var evt = document.createEvent("KeyboardEvent");
evt.initKeyEvent ("keypress", true, true, window,
0, 0, 0, 0,
0, keycode);
var canceled = !body.dispatchEvent(evt);
}
heres the html:
<div id="LeftArrow" onclick="simulateKeyPress(83)">
<a href="#"><img src="PopularGamesImages/LeftArrow.jpg" width = "40px"/></a>
</div>
I would really apreciate it if anyone could help me with my problem, Thanks.