Tech Note 25d: Automatic Keyboard Pop Up

May 01, 2008

© NSB Corporation. All rights reserved.

I received a question:

In text input, how do you display the keyboard screen as soon as the user clicks a field?

I investigated how to do it after dividing it into two actions: "bring the cursor in a field" and "displaying the soft keyboard".

First, I was interested in "displaying the soft keyboard". I searched the keyword "KeyBoard" in the API reference, and found the two API functions:

  • SysKeyboardDialog
  • SysKeyboardDialogV10

These should be prepared to display the keyboard, but SysKeyBoardDialog needs to pass parameters, so I just ignored it and decided to use SysKeyboardDialogV10 which doesn't require a parameter or return a value. API functions like this normally work from NS Basic very easily.

Then, after putting a command button on the screen, I set the following line:

        SysTrapSub 179,0

Compile ... Run ...

Start the keyboard after moving the cursor to an input area.

Because the cursor was not in the field, the error was shown... I thought it looked all right despite the error, so I tried again after setting the cursor.

                

Yes. If the cursor is in the field, tapping the "KEYBOARD" button brings up the soft keyboard.

Next, "bring the cursor in a field". I made a wrong judgment here:
        NS Basic should have "SetFocus" command.

With this assumption, I looked though the handbook, and found this:
        Cursor Id moves the cursor to the specified object

But I couldn't find details; the handbook didn't provide it.
So I tried specifying the field's ID number like:

        Cursor Id 1005

But this is an error.
How about this:

        Cursor Id,1005

This is an error, too.
Next,

        Cursor Id Fld1005

Error.
Maybe I am doing something totally wrong. Finally this one:

        Cursor Id "Fld1005"

It goes through.

So the combination of two lines:
        Cursor Id "Fld1005"
        SysTrapSub 179,0


This works fine. I was satisfied after finding how to use the Cursor Id command, but with some curiosity I checked the NS Basic's message board.

Mmm... I found a message "don't understand CURSOR ID". The person seemed to try the same thing. But I also found a response to the message:

        You'd better use the SetFocus method instead of the Cursor ID command

.... I checked the handbook again. My mistake :-)

        Fld1005.SetFocus
        SysTrapSub 179,0


Yes. This works.