Hello. I have a new blog.

I've moved this blog to the following URL Kerkness.ca. Thank you for visiting, please update your bookmarks.

Wednesday, February 20, 2008

Flex On Screen Qwerty Keyboard Component

NOTE:  I've updated this component. To see the latest version click here.

One of the Flex applications I work on is a touch screen application primarily used to browse a product catalog. Because there is no keyboard physically attached to the touch screen display and it was necessary to have some input from users (primarily for signing up to a mailing list) I built a Qwerty keyboard component for flex.

The component displays a nearly full set of keys found on your standard Qwerty keyboard with a limited set of special characters. You can assign TextInput and TextArea controls to accept the output from the component and there is a handy method for changing focus to different input fields.

Click here to view the example application

Click here to view source

Basic Usage

<mx:Form width="100%">
<mx:FormItem label="Field 1" width="100%">
<mx:TextInput id="field1" focusIn="myQwertyKeypad.newFocus(field1)" width="100%"/>
</mx:FormItem>
<mx:FormItem label="Field 2" width="100%">
<mx:TextInput id="field2" focusIn="myQwertyKeypad.newFocus(field2)" width="100%"/>
</mx:FormItem>
<mx:FormItem label="Field 3" width="100%">
<mx:TextInput id="field3" focusIn="myQwertyKeypad.newFocus(field3)" width="100%"/>
</mx:FormItem>
</mx:Form>
<claire:Qwerty id="myQwertyKeypad" inputControl="{field1}" width="100%"/>


While probably a pointless component for most Flex Applications this component is very handy for touch screen input requirements.

14 comments:

  1. Thank you for the qwerty component, it's really useful!!!

    ReplyDelete
  2. You're welcome. Thanks for the comment. I've found the component useful as well. If you can think of any improvements, please let me know.

    ReplyDelete
  3. Thanks. I find the keyboard cool. Is there any way where I can create an 'Enter' button?

    ReplyDelete
  4. Hi, i find your soft keyboard useful! I had successfully able to filter a list of information by typing into a form from the physical keyboard. But how do i actually filter the list from the key input of the soft keyboard? thanks!

    ReplyDelete
  5. Thank you for the questions and comments. I've updated this component and posted a new example. I've also included instructions on how to add an 'Enter' or 'Return' button to the keyboard so that people have an idea how to customize it.

    ReplyDelete
  6. Great work! Most appreciated!

    ReplyDelete
  7. That's quite a simple solution to a complex problem. I'm impressed. Thank you for posting this.

    ReplyDelete
  8. Hi.. I'm have used your component in my flex application and it worked like a charm!! Thanks for sharing your source codes!!

    I have placed the on screen keyboard in a internal pop up in Flex, and currently i have trouble trying to get the focusManager to type in both fields. Can you give me some advise on how to do this? Thanks a million!!

    ReplyDelete
  9. @Wangi

    When you set the focus to a specific field you need to call the method yourQwerty.setFocus( yourTextInput ); The Qwerty component won't automatically know which field has focus, you'll need to call this method each time the focus shifts. I hope that helps.

    ReplyDelete
  10. Hi Kerk,

    I did try using that method, however, it only focuses on one field rather when i call that method.

    public function setLoginFocus(com:UIComponent):void{
    this.loginKeyPad.newFocus(com);
    }

    ReplyDelete
  11. This component is exactly what I am looking for, but I am having trouble getting it to work. When I copy what is in the source file, I get the error:

    Type was not found or was not a compile-time constant: Qwerty

    Can you tell me how to fix this? I'm still kinda new to Flex.

    ReplyDelete
  12. Hello Beth,
    It sounds like the Flex builder is not able to find the Qwerty component in your project. In the example notice in the application tag the property that reads xmlns:claire="claire.com.*". This tells the Flex builder that the 'claire' components are located in the folder src/claire/com/ This is where the Qwerty.mxml file should be located. If the file is in this folder and you have the necessary xmlns declaration in the application tag you shouldn't get that error. I hope that helps. If not let me know.

    ReplyDelete
  13. Hi Kerk,

    Thanks so much for your help by posting this component. Im having trouble using it in my app though. I have a search function which is called by using "change" in my text field. The touch keyboard displays text in my textfield, however 'change' does not recognise the input from the touch keyboard and does not call my search function. When I use my normal keyboard in the text field 'change' does recognise the key input and calls my search function. I dont know how to fix this and was hoping you could help.

    Regards Ryan

    ReplyDelete
  14. Hi Anonymous,

    We probably need to dispatch a CHANGE event ourselves from the Qwerty.mxml component on the inputControl property. Try adding this line to the method addToString.

    inputControl.dispatchEvent(new Event(Event.CHANGE));

    ReplyDelete

Thank you for the comments.