如何检查用户是否在文本字段中输入?

How do I check if the user is typing in a text field?

您如何检查用户是否正在文本输入(Flex TextArea、TextInput、RichEditableText)中键入内容?

在我的 AIR 应用程序中,我想监听应用程序上的键盘事件,但我只想在它们没有在文本字段中键入内容并且没有其他组件处理它时做出响应。

比如我想听A键和运行一个命令。但前提是他们没有在文本字段中输入内容。

仅供参考,我添加了一个 NativeFlexMenu 并为 A 添加了键盘修饰符,即使用户在文本字段中键入,它也会捕获键事件。

这似乎在添加到应用程序后起作用。这样做的一个问题是,如果文本字段具有焦点,即使您单击该应用程序,它也会继续具有焦点。我可能会尝试添加一个点击事件处理程序来改变焦点。

<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication keyUp="application1_keyUpHandler(event)"
                       keyDown="application1_keyDownHandler(event)">
</s:WindowApplication>

protected function application1_keyDownHandler(event:KeyboardEvent):void {
    var keyCode:int = event.keyCode;
    var applicable:Boolean;
    var focusedObject:Object;
    var target:Object = event.target;

    if (keyCode==Keyboard.A || 
        keyCode==Keyboard.B || 
        keyCode==Keyboard.C) {

        if (!event.controlKey && !event.commandKey) {
            applicable = true;
        }
    }

    if (!applicable) return;

    focusedObject = focusManager.getFocus();

    if (focusedObject is Application || event.target is Stage) {
        isApplication = true;
    }

    //var t:int = getTimer();
    if (target is RichEditableText ||
        focusedObject is IEditableText ||
        focusedObject is SkinnableTextBase ||
        focusedObject is TextField ||
        focusedObject is FTETextField ||
        focusedObject is FlexHTMLLoader ||
        focusedObject is ComboBox) {
        applicable = false;
    }
    //trace("time:" + (getTimer() - t)); takes 0 ms

    if (applicable) {
        if (keyCode==Keyboard.A) {
            // do something
        }
        else if (keyCode==Keyboard.B) {
            // do something
        }
        else if (keyCode==Keyboard.C) {
            // do something
        }
    }
}