Possible Duplicate:
Simulate JavaScript Key Events
--EDIT--
Long story short I have a swiffy object on the page and I can "control" it using different keypresses and one of them is by pressing "P".. right now, if I physically press P it performs a given animation... The code below is not working because that animation isn't happening after the 2 seconds... (I've added alert's to test and it fires, but the actual keypress simulation doesn't work...
If your curious, this is purely for animation purposes... I'm building a rapid-prototype... maybe I should be asking how to control a swiffy object (the same way the letter P does it) instead of asking how to fake the letter P press? o.o
Anyway, is this even possible?
--EDIT--
heads-up: I'm pretty new to jQuery and JavaScript so I apologize for the question. I've searched the site for my question and found a closed thread, but since I can't make it work I'm opening this new one.
So basically I want to simulate/fake a keypress of the letter P. From that closed thread it looked like it's possible and here's what I got:
setTimeout(function() { triggerP() }, 2000);
function triggerP()
{
var evP = jQuery.Event("keypress");
evP.which = 112;
$(this).trigger(evP);
}
I also have this (just wanted to make sure I have a proper version that allows for this):
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js" type="text/javascript"></script>
Is there anything wrong with the code above? It's not working!
Thanks!