如何用语言查找字符按键? [英] How to find out the character pressed key in languages?
问题描述
我不能在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属性是当前
字符集中该键的数字
值(默认字符
设置为支持ASCII的UTF-8)。
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屋!