我无法在 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/