我正在尝试模拟按下 TAB 键。我搜索了很长一段时间,没有找到答案。
我尝试过:
dispatchEvent(new KeyboardEvent(KeyboardEvent.KEY_DOWN, true, false, Keyboard.TAB, 0, 0, false, false, false);
但是什么也没发生..
关于我做错了什么的任何提示吗?如何模拟键盘按下?
最佳答案
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 .
你想实现什么目标? 将焦点转移到 UI 元素上? Then check this .
插入制表符空格? Then check this out .
关于events - ActionScript 模拟键盘按下,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11449555/