2016-01-08 105 views
0

如何檢查用戶是否正在輸入文本輸入(Flex TextArea,TextInput,RichEditableText)?如何檢查用戶是否正在輸入文本字段?

在我的AIR應用程序中,我想要監聽應用程序上的鍵盤事件,但我只想響應它們是否未輸入文本字段並且沒有其他組件處理它。

例如,我想收聽A密鑰並運行命令。但只有當他們沒有輸入到文本字段。

僅供參考我添加了一個NativeFlexMenu併爲其添加了鍵盤修改器A,它即使在用戶在文本字段中輸入時也捕獲鍵事件。

+0

我會看看FocusEvents文本輸入;禁用焦點上的菜單熱鍵並使其無法聚焦。 – Brian

+0

嘗試創建一個超出舞臺大小的TextField,並通過方法向他詢問焦點stage.focus = outsideTextField; –

回答

1

這似乎工作時添加到應用程序。與此相關的一個問題是,如果文本字段具有焦點,即使您單擊該應用程序,它也將繼續保持焦點。我可能會嘗試添加單擊事件處理程序來更改焦點。

<?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 
     } 
    } 
} 
相關問題