如何在Flex / AIR中警告用户启用CAPS LOCK?

时间:2008-12-18 14:07:54

标签: flex air

与XP登录界面类似,在Flex 3中,如何在启用了CAPS LOCK键的文本框中向用户显示警告?

3 个答案:

答案 0 :(得分:5)

flash.ui.Keyboard.capsLock不可绑定,因此代码无法正常工作。

我会在TextInput的“keyDown”事件中调用一个函数,然后检查该函数中的flash.ui.Keyboard.capsLock。然后,您可以在该文本上设置visible / includeInLayout,弹出警报等...

答案 1 :(得分:3)

试试这个

private function addHandler():void{
        //Called from app's creation complete event.
        //Listener to handle any keyboard KEY_DOWN event:
        this.addEventListener(KeyboardEvent.KEY_DOWN,handleKeyDown);
    }


private function handleKeyDown(event:KeyboardEvent):void{
     if (Keyboard.capsLock){
          lblCaps.visible =true;
     } else {
          lblCaps.visible =false;   
     }
}

在创建完成时调用addHandler

答案 2 :(得分:1)

在actionScript中:


if(flash.ui.Keyboard.capsLock){
    // caps lock is on...
}

或MXML:


<mx:Box width="100%" id="capsbox"
    visible="{flash.ui.Keyboard.capsLock}" 
    includeInLayout="{capsbox.visible}">
        <mx:Text text="Caps Lock is on." color="red" />
</mx:Box>