apache-flex - 如何找出语言中按下的字符?

标签 apache-flex events actionscript keyboard flex4

我无法在 KeyboardEvent 中使用 charCode 或 keyCode 来找出按下的字符,因为即使我更改键盘布局,charCode 和 keyCode 也不会改变(如果按下相同的键)。

那么,如何根据当前的键盘布局找到被按下的字符呢?

我已经找到了this question ,但是文件说的是:

The charCode property is the numeric value of that key in the current character set (the default character set is UTF-8, which supports ASCII).

不正确。

编辑:我正在使用 Flex 4。

最佳答案

我找到了解决方案。

我们可以监听 TextEvent。此事件不仅会分派(dispatch)给文本组件,还会分派(dispatch)给所有实现 UIComponent 的焦点组件。

例如:

package champjss
{
    import flash.events.TextEvent;
    import mx.core.UIComponent;

    public class EditorComponent extends UIComponent
    {
        public function EditorComponent()
        {
            super();

            addEventListener(TextEvent.TEXT_INPUT, handleTextEvent);
            setFocus();
        }

        protected function handleTextEvent(event:TextEvent):void
        {
            // This text the text that user types,
            // following to current keyboard layout ;)

            trace(event.text);
        }
    }
}

关于apache-flex - 如何找出语言中按下的字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4537349/

相关文章:

java - 自定义按键事件

Jquery如何在动态创建的元素上绑定(bind)点击事件?

apache-flex - 有没有办法将另一个类的成员函数作为参数传递给as3中的函数?

apache-flex - 如何在 ItemRenderer 中使用超出数据网格范围的变量?

apache-flex - 如何使用虚拟布局获取 Spark List 上的可见项

winforms - 订阅表单中所有控件的鼠标事件

events - ActionScript 模拟键盘按下

actionscript - 现有的 swf mp4 播放器?

apache-flex - 柔性 : Capitalize words in string?

actionscript-3 - 在as3中从bytearray播放声音