Пример #1
0
/*----------------------------------------------------------------------*\
 *  Function:	unsigned int _pSLsys_getkey (void);
 *
 * wait for and get the next available keystroke.
 * Also re-maps some useful keystrokes.
 *
 *	Backspace (^H)	=>	Del (127)
 *	Ctrl-Space	=>	^@	(^@^3 - a pc NUL char)
 *	extended keys are prefixed by a null character
\*----------------------------------------------------------------------*/
unsigned int _pSLsys_getkey (void)
{
   /* Check the input buffer because _pSLsys_input_pending may have been
    * called prior to this to stuff the input buffer.
    */
   if (SLang_Input_Buffer_Len)
     return SLang_getkey ();

   if (SLw32_Hstdin == INVALID_HANDLE_VALUE)
     return SLANG_GETKEY_ERROR;

   while (1)
     {
	int status;

	if (SLKeyBoard_Quit)
	  return SLang_Abort_Char;

	status = _pSLsys_input_pending (600);
	if (status == -1)
	  return SLANG_GETKEY_ERROR;

	if (status > 0)
	  return SLang_getkey ();
     }
}
Пример #2
0
unsigned int _pSLsys_getkey ()
{
   unsigned int c;
   unsigned char scan;


   if (!keyWaiting())
     {
	int tsecs = 300;
	while (!_pSLsys_input_pending(tsecs))
	  ;
     }

   /* read codes from buffer */
   RequestSem();
   startBuf = (startBuf + 1) % BUFFER_LEN;
   c = threadKeys [startBuf].ascii;
   scan = threadKeys [startBuf].scan;
   ReleaseSem();

   switch (c)
     {
      case 8:
	if (scan == 0x0E) c = 127;
	break;

      case 0xE0:
      case 0:
	c = _pSLpc_convert_scancode (scan, 0, 1);
	break;

      default:
	break;
     }
   return (c);
}
Пример #3
0
unsigned int _pSLsys_getkey (void)
{
   unsigned char c;

   if (TTY_Inited == 0)
     {
	int ic = fgetc (stdin);
	if (ic == EOF) return SLANG_GETKEY_ERROR;
	return (unsigned int) ic;
     }

   while (1)
     {
	int ret;

	if (SLKeyBoard_Quit)
	  return SLang_Abort_Char;

	if (0 == (ret = _pSLsys_input_pending (100)))
	  continue;

	if (ret != -1)
	  break;

	if (errno == EINTR)
	  {
	     if (-1 == handle_interrupt ())
	       return SLANG_GETKEY_ERROR;
	     
	     if (SLKeyBoard_Quit)
	       return SLang_Abort_Char;

	     continue;
	  }

	if (SLKeyBoard_Quit)
	  return SLang_Abort_Char;

	break;			       /* let read handle it */
     }

   while (1)
     {
	int status = read(SLang_TT_Read_FD, (char *) &c, 1);

	if (status > 0)
	  break;

	if (status == 0)
	  {
	     /* We are at the end of a file.  Let application handle it. */
	     return SLANG_GETKEY_ERROR;
	  }

	if (errno == EINTR)
	  {
	     if (-1 == handle_interrupt ())
	       return SLANG_GETKEY_ERROR;

	     if (SLKeyBoard_Quit)
	       return SLang_Abort_Char;

	     continue;
	  }
#ifdef EAGAIN
	if (errno == EAGAIN)
	  {
	     sleep (1);
	     continue;
	  }
#endif
#ifdef EWOULDBLOCK
	if (errno == EWOULDBLOCK)
	  {
	     sleep (1);
	     continue;
	  }
#endif
#ifdef EIO
	if (errno == EIO)
	  {
	     _pSLang_verror (SL_Read_Error, "_pSLsys_getkey: EIO error");
	  }
#endif
	return SLANG_GETKEY_ERROR;
     }

   return((unsigned int) c);
}