Keyboard Handler

Previous  Next

 

The keyboard handler is used to handle the INKEY$ and the OPTION BREAK settings.  As with the input and output handlers, we have 2 versions of the keyboard handlers, with and without the mb_interpreter_t parameters.  It's recommended to use the extended version (_ex) with mb_interpreter_t parameter.

 

Example

 

static int _check_keyboard( mb_interpreter_t* s, short int* pKey, short int break_key );

 

mb_set_check_keyboard_handler( bas, _check_keyboard );

 

/////////////////////////////////////////////////////////////////////////////

//

static int _check_keyboard( mb_interpreter_t* s, short int* pKey, short int break_key )

{

  if ( mb_get_environment( s ) == ENV_WINDOWS )

     {

     // Pass it to our Window MB2 Console DLL

     return MB2Console_OnCheckKeyboard( pKey, break_key );

     }

  else

     {

     if ( _kbhit() )

        {

        int key = getch();

 

        if ( key == break_key )

        {

           // Abort and Terminate

           printf( "<BREAK>" );

           return MB_FUNC_BYE;

        }

        if ( pKey )

        {

           // Return the key pressed

           *pKey = key;

        }

     }

  }

 

  return MB_FUNC_OK;

}