如何找出语言中的字符按键? [英] How to find out the character pressed key in languages?

查看:27
本文介绍了如何找出语言中的字符按键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I can't use charCode, or keyCode in KeyboardEvent to find out the character pressed, because even if I change the keyboard layout, charCode and keyCode are not change (if press the same key).

那么,如何找到按下的字符,跟随当前的键盘布局?

So, how to find the presssed character, following to the current keyboard layout?

我已经找到了这个问题,但是文档上说的是:

I already found this question, but what the document said:

charCode 属性是数字该键在当前的值字符集(默认字符设置为UTF-8,支持ASCII).

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.

I am using Flex 4.

推荐答案

我找到了解决方案.

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

We can listen for TextEvent. This event not only dispatches to text components, but also all focused components that implement 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);
        }
    }
}

这篇关于如何找出语言中的字符按键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆