mb_set_check_keyboard_handler

Previous  Next

 

status_t mb_set_check_keyboard_handler( mb_interpreter_t* s, mb_check_keyboard_t pHandler )

 


 

Set the keyboard handler.  To remove the handler, supply NULL.  This format uses the standard handler format.

 

typedef int (*mb_check_keyboard_t)( short int* pKey, short int break_key );

 

Example

 

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

//

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

  {

  if ( mb_get_environment( g_bas ) == ENV_WINDOWS )

     {

     return MB2Console_OnCheckKeyboard( pKey, break_key );

     }

  else

     {

     if ( g_ctrlC )

        {

        g_ctrlC = FALSE;

 

        if ( break_key == 3 )

           {

           printf( "<BREAK>" );

           return MB_FUNC_BYE;

           }

        endif

        }

     else if ( _kbhit() )

        {

        int key = getch();

 

        if ( key == break_key )

           {

           printf( "<BREAK>" );

           return MB_FUNC_BYE;

           }

        endif

 

        if ( pKey )

           {

           *pKey = key;

           }

        endif

        }

     endif

     }

  endif

 

  return MB_FUNC_OK;

  }

endfunc

 

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

//

static void _setup_basic_interpreter( mb_interpreter_t* s, CConsoleCmdLineInfo::RUN_E eEnvironment )

  {

  // MyBASIC Environments defined from 0 (ENV_NONE) to 6 (ENV_MAXGRAPH) so we need to convert

  // If we're not running, set environment to ENV_NONE.  This is the same as running in cmd window

 

  int nEnvironment = eEnvironment > CConsoleCmdLineInfo::eNORUN ? int( eEnvironment ) - 1 : ENV_NONE;

 

  mb_set_environment( s, nEnvironment );

  mb_set_error_handler( s, _on_error );

  mb_set_inputer( s, _getstring );

  mb_set_printer( s, _printstring );

  mb_set_check_keyboard_handler( s, _check_keyboard );

  }

endfunc