Detect Keyboard State change

Version 2

    Verified Product Versions

    Wavelink Naurtech CETerm 5.7

    For IBM emulations (5250 and 3270), the host application can prevent data input during certain times. If data is input during such time, either using a keyboard or by scanning a barcode, a protocol error is flagged. In order to minimize such errors, the scripting engine provides a way to detect the change in input status for the keyboard.

     

    The OnKeyboardStateChange( session, state) is a new event that was added in version 5.5. It is used to detect the various keyboard inhibit states. It is fired when the state of the keyboard is changed by a user or host action. Typically this event is only used with IBM sessions. A VT session may generate this event only if custom escape sequences lock the keyboard. It is useful to disable the scanner when say the IBM host has entered the session in a keyboard inhibit state. This handler can thus prevent users from accidentally scanning data at such time.

     

    This sample script implements a handler for the keyboard state change event. It validates the new state passed in as an argument to the handler. If the keyboard state is "Unlocked", the the scanner is enabled. If it is "locked" then the scanner is disabled.

     

    // OnKeyboardStateChange( session, state )

     

    var IBM_KEYBOARD_HARDWARE_ERROR = 0;

    var IBM_KEYBOARD_NORMAL_LOCKED = 1;

    var IBM_KEYBOARD_NORMAL_UNLOCKED = 2;

    var IBM_KEYBOARD_POWER_ON = 3;

    var IBM_KEYBOARD_PRE_HELP_ERROR = 4;

    var IBM_KEYBOARD_POST_HELP_ERROR = 5;

    var IBM_KEYBOARD_SS_MESSAGE = 6;

    var IBM_KEYBOARD_SYSTEM_REQUEST = 7;

     

    var PreviousKeyboardState = 0;

     

    function OnKeyboardStateChange( session, state )

    {

        // DEBUG: Show state

        // OS.Alert(" KeyboardStateChange session=" + session + " state=" + state );

     

        // Autoreset if user made a keying error.

        if (state == IBM_KEYBOARD_PRE_HELP_ERROR)

        {

            //CETerm.PostIDA( "IDA_RESET", session );

        }

     

        // Disable scanner if keyboard is locked.

        if (state == IBM_KEYBOARD_NORMAL_UNLOCKED)

        {

            if (PreviousKeyboardState != IBM_KEYBOARD_NORMAL_UNLOCKED)

            {

                CETerm.PostIDA( "IDA_SCAN_RESUME", 0 );

            }

        }

        else

        {

            if (PreviousKeyboardState == IBM_KEYBOARD_NORMAL_UNLOCKED)

            {

                CETerm.PostIDA( "IDA_SCAN_SUSPEND", 0 );

            }

        }

     

        // Save new state

        PreviousKeyboardState = state;

    }