tk66
tk66

Reputation: 284

ActionScript simulate keyboard press

i am trying to simulate the pressing of the TAB key. I have search for quite a while and found no answer to that.

I tried:

dispatchEvent(new KeyboardEvent(KeyboardEvent.KEY_DOWN, true, false, Keyboard.TAB, 0, 0, false, false, false);

but nothing happens..

any hints on what i am doing wrong? How can i simulate the keyboard press?

Upvotes: 2

Views: 2278

Answers (1)

Marco Kerwitz
Marco Kerwitz

Reputation: 5494

You can't completely recreate a key being pressed since that is all user input and not programmatic. However, a program reacts (mostly) to user input through events. By invoking an event through dispatchEvent you are (mostly) recreating what would happen if that event originated through user input.

source.

What are you trying to achieve? Switching focus on UI-Elements? Then check this.

Inserting tab space? Then check this out.

Upvotes: 2

Related Questions