Controlling the soft keyboard in Flex Mobile applications

There are times when writing mobile apps that you want to have more fine grained control over the software keyboard and Flex 4.5 makes this very easy.

Any object based on InteractiveObject now has a needsSoftKeyboard property, setting this to true will cause the virtual keyboard to come up on the device whenever the instance is given focus.

For example here we have a Button component where we can set the needsSoftKeyboard property to true. As soon as it gets focus when clicked the soft keyboard will trigger. By default the Button component obviously doesn’t have this behaviour.

 

[cc lang=”mxml”]

[/cc]

 

Apart from setting the needsSoftKeyboard property you can also control it through an ActionScript call. In the example below we trigger the soft keyboard to appear as soon as the view is ready.

[cc lang=”mxml”]

[/cc]

 

When the virtual keyboard triggers there are a few events that fire. The first one is “softKeyboardActivating” that indicates the keyboard is about to open and “softKeyboardActivate” which is dispatched right after the keyboard is made available. Likewise there is a “softKeyboardDeactivate” event that gets fired after the virtual keyboard is dismissed.

The SoftKeyboardEvent that gets triggered has two interesting properties, one is triggerType and can have either a value of “contentTriggered” (when the keyboard was triggered through ActionScript) or “userTriggered” when it was triggered through user interaction.

Another property we can get through the event is relatedObject, which is a reference to the InteractiveObject instance that is responsible for triggering the soft keyboard.

[cc lang=”mxml”]

[/cc]

 

Finally, there might be uses cases where you want to prevent the default behaviour of a soft keyboard showing up. For example when you don’t want to show the soft keyboard when a TextInput component gets given focus. To do this you need to prevent the default behaviour in the softKeyboardActivating event.

[cc lang=”mxml”]

[/cc]

 

Advertisements

7 thoughts on “Controlling the soft keyboard in Flex Mobile applications

  1. Excellent Explanation of how to get the soft keyboard up,and working in Flex 4.5.
    Thank You Peter

  2. I have used the same approach in my application. The only problem that i encountered was when the softkeyboard was deactivated using the hide (down arrow) button from the keyboard which is at the bottom left corner. A softkeyboard deactivate event should be fired at this time, but it wasnt in my case. did it happen with your app too ? Any idea whats happening here.

  3. Blade vision says:

    Very Nice.
    I am using Flash Builder Burrito sdk 4.5 and have installed Flash player 10.2 but needsSoftKeyboard method is not avilable here.
    What i am missing please help me to configure this so i can access this method.
    Thanks.

  4. Blade vision says:

    Please tell me about can we detect which language is active at the moment in android mobile using Flex 4.5
    Thanks a lot.

  5. Keith says:

    Does anyone know of a way to set the the first character to capitalize on the soft keyboard (ie: native iOS keyboard behavior)?

    Thanks

Comments are closed.