Can I programmatically press the arrow keys in javascript or jquery?

I am trying to programmatically press the arrow keys using javascript or jquery. I did not find a suitable solution for this. Do you guys have any ideas? any examples?

+4
source share
2 answers

I do not know how to fire events in the whole browser. But you can activate individual elements on your page.

<body>
    <script>
       leftArrowKey = 37
       upArrowKey = 38
       rightArrowKey = 39
       downArrowKey = 40

       e = jQuery.Event("keydown");
       e.which = leftArrowKey;
       $("myInput").trigger(e);
    </script>

    <object allowScriptAccess="always" id="myInput" ... >
        ...
    </object>
</body>

To send this event to a flash animation, add allowScriptAccess = "always" to the Object tag that you are using.

+2
source

you can fire click events by doing

$(selector).trigger('click');

, ? http://api.jquery.com/trigger/

0

All Articles