Topic automatically display keyboard after dynamically adding keyboard

We have two new locations for Keyman technical support:

The Tavultesoft Forums are now read only.


# automatically display keyboard after dynamically adding keyboard   2014-12-14 19:15:09.573
Matt
I am using Keymanweb 2.0 build 396.

I am able to dynamically add a keyboard from a html select list on a form.

However, after the keyboard is added to the form I would like the keyboard to be automatically displayed to the user.

The following code does add the keyboard to the form, but does not display the keyboard to the form. The user must manually mouse click on the keyboard from the keyboard menu to display the keyboard.

Here is my code:

:

    .......

    (function(kmw) {
   
        kmw.init();
   
        if ($("#id_language_code").val() == 'ar' ) {
       
            kmw.addKeyboards('arabic_101'); // this will add the keyboard.
       
            kmw.setActiveKeyboard('Keyboard_arabic_101','arb'); // this should display the vkb to the user.

        } else if ($("#id_language_code").val() == 'ru' ) {
       
            kmw.addKeyboards('russian'); // this will add the keyboard.
       
            kmw.setActiveKeyboard('Keyboard_russian','rus'); // this should display the vkb to the user.

        }
       
        .........
       
    }


Am I using setActiveKeyboard correctly and the internal keyboard name & language code correctly?

I have noticed that after the keyboard has been manually activated the first time (manually mouse click on the keyboard in the keyboard menu), the keyboard is displayed whenever the language code / keyboard is again selected from the html select list by the user.

It seems that the keyboard must be selected by the user manually after being added.
# RE: automatically display keyboard after dynamically adding keyboard   2014-12-15 15:51:17.470
Matt
Doh! That should be Keymanweb 2.0 build 374 - not 396!
# RE: automatically display keyboard after dynamically adding keyboard   2014-12-15 16:07:45.957
Marc Durdin
Tavultesoft Staff
Sorry Matt, I don't have an immediate answer -- John will be back in the morning and can respond then.
# RE: automatically display keyboard after dynamically adding keyboard   2014-12-18 15:53:42.463
Matt
Any suggestions would be appreciated.
# RE: automatically display keyboard after dynamically adding keyboard   2014-12-18 16:10:29.560
Marc Durdin
Tavultesoft Staff
I'll ask John to take a look when he gets a chance. Hopefully in next couple of days.
# RE: automatically display keyboard after dynamically adding keyboard   2014-12-19 11:43:22.580
John Durdin
Hi Matt,

The steps needed are:
1. add the keyboard (using addKeyboards).
2. wait until it has been added and is available to be selected
3. select that keyboard, specifying both the (internal) keyboard name and language code
4. set the focus to any editable element (otherwise the OSK will not appear)
5. tell KeymanWeb to display the OSK

Here is one way you can do that:

Include the following function:

:
 function useKeyboard(kbdName,elId)
  {
    var kmw=tavultesoft.keymanweb,kbd=kmw.getKeyboard('Keyboard_'+kbdName); 
    if(kbd == null)
    {
       var tWait=(arguments.length > 2 ? arguments[2] : 10000);
       if (tWait > 0) window.setTimeout(function () { useKeyboard(kbdName, elId, tWait - 50); }, 50);
    }
    else
    {
          kmw.setActiveKeyboard(kbd.InternalName, kbd.LanguageCode);
          document.getElementById(elId).focus();
          kmw.osk.show(1);     
    }
  }


then call it with the keyboard name and an element id after your call to addKeyboards(), for example:

:

      kmw.addKeyboards('arabic_101');
      useKeyboard('arabic_101','ta1');


Hope that helps.
# RE: automatically display keyboard after dynamically adding keyboard   2014-12-20 10:22:42.943
Matt
Thanks John.

That works a treat.