I want to build a small script which triggers the jump move in a Windows fangame. In the game, the jump key is "Z" (KeyCode 90 in my case). So I built this script:
var press = jQuery.Event("keypress");
press.ctrlKey = false;
press.which = 90;
setInterval(function() { $("whatever").trigger(press) }, 2000 );
But when I execute it, nothing happens (I tested it with Firefox). I added console.log("Done")
to the function just to see if it works, and it did. I also tried using a textbox seeing if it would maybe write the letters there, but it didn't as well. It's like the event gets ignored by JS.
Can I do something like that in the Browser? Or is it impossible to do so?
Thanks in advance
I want to build a small script which triggers the jump move in a Windows fangame. In the game, the jump key is "Z" (KeyCode 90 in my case). So I built this script:
var press = jQuery.Event("keypress");
press.ctrlKey = false;
press.which = 90;
setInterval(function() { $("whatever").trigger(press) }, 2000 );
But when I execute it, nothing happens (I tested it with Firefox). I added console.log("Done")
to the function just to see if it works, and it did. I also tried using a textbox seeing if it would maybe write the letters there, but it didn't as well. It's like the event gets ignored by JS.
Can I do something like that in the Browser? Or is it impossible to do so?
Thanks in advance
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.