1 Reply Latest reply on Aug 3, 2010 6:22 AM by BhaskerChari

    Alerting the User when CAPS Lock is ON duirng Loigin

    kiran7881 Level 1

      Hi ,

       

      I am developing a Login Page , i need to alert the User if the CAPS Lock is ON .

       

      I have tried this but this isn't working , can you please help me in achieving this .

       

      On to the LoginPage Login.mxml creationComplete i am calling a function CallMe()

       

      function CallMe():void
      {

         if (Keyboard.capsLock){

      Alert.show("Caps Lock Is On");
                   }
      else
      {
      Alert.show("Caps Lock Is OFF");
      }
      }

       

      On to the above code always (even though the CAPS lock is ON Or OFF) the Alert
      Alert.show("Caps Lock Is OFF"); is always executed .

       

      Could you please help me on this .

       

       

      Thanks in advance .

        • 1. Re: Alerting the User when CAPS Lock is ON duirng Loigin
          BhaskerChari Level 4

          Hi Kiran,

           

          Check the simple code below:

           

          Note: Here the main thing is the focus should be there in the TextInput...so put focus in Your Username textinput of your Login page...and add the KeyDown listener as shown below in your main mxml...

           

           

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()">
          <mx:Script>
            <![CDATA[
             import mx.controls.Alert;


                   private function init():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){
                         Alert.show("Caps Lock Is On");
                       }
                       else
                       {
                        Alert.show("Caps Lock Is Off");
                       }
                      
                   }

            ]]>
          </mx:Script>

          <mx:TextInput width="200" height="25" />
          </mx:Application>

           

          If this post answers your question or helps, please kindly mark it as such.


          Thanks,

          Bhasker Chari