⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 kb_input.c

📁 功能强大的文本编辑器
💻 C
📖 第 1 页 / 共 5 页
字号:
/************************/

void sleep_msec (int time_delay)  /* MS_DOS */
{

#if 0   /* LSB = 1 sec */

time_t time_start,time_act;

   time_delay /= 1000;    /* LSB: msec --> sec */

   for ( time(&time_start) , time(&time_act) ;
         (int)(time_act - time_start) < time_delay  ;
         time(&time_act))
   {
   }

#else   /* LSB = 10 msec */

struct dostime_t time_start, time_act;
int msec10_start, msec10_act;

   time_delay /= 10;    /* LSB: msec --> msec10 */

   _dos_gettime (&time_start);
   msec10_start = (int) time_start.second * 100 +
                  (int) time_start.hsecond;
   for (;;)
   {
      _dos_gettime(&time_act);
      msec10_act = (int) time_act.second * 100 +
                   (int) time_act.hsecond;
   
      if ((((msec10_act - msec10_start) + 6000) % 6000) >= time_delay)
         break;     
   }

#endif

   return;
}  /* sleep_msec (MS_DOS) */


/************************/
/*  is key pressed ?    */
/************************/

#define INPUT_VIA_BIOS 1  /* muss auf 1 stehen, wenn input redirection */

int loc_key_pressed (void)
{
/* return true, if key is pressed, else false */

   if (input_redirected) return 0;

#if (INPUT_VIA_BIOS)
   return _bios_keybrd(_KEYBRD_READY);
#else
   return kbhit ();
#endif
}

/* -FF-  */

/************************/
/*  get 1 key stroke    */
/************************/

static int loc_get_1_int (void)
{
/* This functions returns special keys (function, cursor keys, ...) */
/* in one (modified) int.   */

int key;

#if (WITH_MOUSE)
int call_handler;
#endif


   if (input_redirected)
   {                          /* input from file (stdin) */
      key = getchar ();

      return check_end_of_file (key);
   }
   else
   {                          /* input from keyboard direct */
   
#if (INPUT_VIA_BIOS)

#if (WITH_MOUSE)
   /* poll keyboard and mouse alternating */
      for (;;)
      {
      /* is key pressed ? */
         if (_bios_keybrd(_KEYBRD_READY))
         {
            MouHideMouse ();
            break;
         }

      /* mouse event ? */
         call_handler = -1;       /* don't call */
         if (mouse_event())
         {
            call_handler = 0;     /* call because event */
         }
         else
         {
            if (mouse_get_left_button ())
               call_handler = 1;  /* call because repetition */
         }

         if (call_handler >= 0)
         {
            key = mouse_event_handler_c (call_handler);
            if (key)           /* return value != 0 means: */
            {
               MouHideMouse ();
               return (key);   /* mouse simulated key stroke */
                               /* e.g.: left mouse key = <cr> */
            }

         /* make mouse visible */
            MouHideMouse ();
            MouShowMouse ();
         }
      }
#endif

   
   /* special keys are transferred as MSB            */
   /* in return value of _bios_keybrd, with LSB = 0. */
   
      key = _bios_keybrd(_KEYBRD_READ);
   
      if ((key & 0xff) != 0)
         return (key & 0xff);       /* normal key, return LSB direct (positiv) */
      else
         return (((key >> 8) & 0xff) - 256);  /* special key,
                                                 return MSB modified (negativ) */
   
#else
   
   /* special keys (function, cursor keys, ...) are transferred as */
   /* a sequence of two ints (with the first int = 0).             */
   
      key = getch();
   
      if (key != 0)
         return key;              /* normal key, return direct (positiv) */
      else
         return (getch() - 256);  /* special key, return modified (negativ) */
   
#endif
   }

}  /* loc_get_1_int */

/* -FF-  */

/************************/
/*  echo on / off       */
/************************/


void kb_echo_off (void)
{
#if (TEST_PRINT)
   printf ("\n>>> kb_echo_off: input_redirected = %d \n", input_redirected);
#endif

   set_wrap_off ();

   return;
}  /* kb_echo_off */


void kb_echo_on (void)
{
#if (TEST_PRINT)
   printf ("\n>>> kb_echo_on: input_redirected = %d \n", input_redirected);
#endif

   set_wrap_on ();

   return;
}  /* kb_echo_on */

#elif (ACT_OP_SYSTEM == WIN_32)  /*  */

/*****************************************/
/*                                       */
/*           WIN_32 region               */
/*                                       */
/*****************************************/

/************************/
/*  n msec's delay      */
/************************/

void sleep_msec( int wait )
{
   Sleep(wait);
}


/************************/
/*  is key pressed ?    */
/************************/

int loc_key_pressed (void)
{
/* return true, if key is pressed, else false */

   if (input_redirected) return 0;

   return kbhit ();
}

/************************/
/*  get 1 key stroke    */
/************************/

static int loc_get_1_int (void)
{
/* This functions returns special keys (function, cursor keys, ...) */
/* in one (modified) int.   */

int key;

   if (input_redirected)
   {                          /* input from file (stdin) */
      key = getchar ();

      return check_end_of_file (key);
   }
   else
   {                          /* input from keyboard direct */
   

   /* special keys (function, cursor keys, ...) are transferred as */
   /* a sequence of two ints (with the first int = 0 or = 0xE0).   */
   
      key = getch();
   
      if ((key != 0) && (key != 0xE0))
         return key;              /* normal key, return direct (positiv) */
      else
         return (getch() - 256);  /* special key, return modified (negativ) */
   
   }

}  /* loc_get_1_int */

/* -FF-  */

/************************/
/*  echo on / off       */
/************************/


void kb_echo_off (void)
{
#if (TEST_PRINT)
   printf ("\n>>> kb_echo_off: input_redirected = %d \n", input_redirected);
#endif

   set_wrap_off ();

   return;
}  /* kb_echo_off */


void kb_echo_on (void)
{
#if (TEST_PRINT)
   printf ("\n>>> kb_echo_on: input_redirected = %d \n", input_redirected);
#endif

   set_wrap_on ();

   return;
}  /* kb_echo_on */


#elif (ACT_OP_SYSTEM == QNX)

/* -FF-  */

/*****************************************/
/*                                       */
/*    QNX pterm ansi                     */
/*                                       */
/*****************************************/


/************************/
/*  get 1 key stroke    */
/************************/

static int loc_get_1_int (void)
{
/* translation from <esc> sequences in one single (negativ) int */

/* special keys (function, cursor keys, ...) are transferred as */
/* <esc> sequence with variable no of chars.                    */
/* This functions returns special keys in one (modified) int.   */

#define ALLOW_SLOW_CONNECTIONS 1   /* to surround problems with <ESC>s */
                                   /* @@ implement time survey !! */

int ii, last_key, result, value;

static int key;
static int esc_buff;   /* if a single <esc> is followed by a sequence,  */
                       /* this event must be handled in special manner. */ 

static int old_mode_flag, old_text_area, old_toggle;
static time_t act_time, esc_time, delta_time;
#define MAX_ESC_TIME 5   /* LSB = 1 Sec. */
char err_text [20];

/* NEU !! */
   last_key = key;

/* NEU ! output buffer leerraeumen */
   fflush (stdout);

/* is there still a char in the queue ? */
   if (esc_buff)
   {
      key = esc_buff;        /* take it */
      esc_buff = 0;          /* clear buffer */
   }
   else
   {
      key = get_1_byte ();   /* get new byte from stdin */
   }


/* EOF bei input redirection ? */
   key = check_end_of_file (key);


/* input from file ? */
   if (input_redirected)
      return key;


/* <esc> handling */
#if (!ALLOW_SLOW_CONNECTIONS)
   if (key == 0x1b)            /* is it <esc> ? */
#else
   if ((key == 0x1b) ||
       ((key == '[') && (last_key == 0x1b)))
#endif
   {
   /* are there characters following immediately ? */
      if (key == 0x1b)
      {
         esc_time = time (NULL);
         result = get_1_byte_with_timeout (esc_waittime);
      }
      else
      {
      /* sequence: <esc> '[' (until now) */

      /* check time since <esc> */
         act_time = time (NULL);
         delta_time = act_time - esc_time;

         if (delta_time > MAX_ESC_TIME)
         {
            result = -1;   /* absolute timeout */
         }
         else
         {
            result = key;   /* '[' */
            if (old_mode_flag || old_text_area || old_toggle)
            {                             /* gimme just a little more time */
               esc_waittime = max (esc_waittime, 50);    /* min. 50 msec   */
               esc_waittime = (esc_waittime * 16) / 10;  /* factor 1.6     */
               esc_waittime = min (esc_waittime, 1000);  /* max. 1000 msec */
               sprintf (err_text, " (AE=%d msec)", esc_waittime);
               err_message_1 (ESCAPE_SEQUENCE_ERROR, err_text);
            }
         }
      }
                                       /* != 0, if in:                   */
      old_mode_flag = mode_flag;       /* insert / exchange mode         */
      old_text_area = text_area;       /* status line 2 / history window */
      old_toggle    = save_d.toggle;   /* 'B'uffer / 'D'elete            */


      if (result < 0)           /* timeout ? */
      {                         /* yes : single <esc> */
         return key;            /* send it ! */
      }
      else                      /* no : <esc> sequence */
      {
/* search tag: qnx ansi */

         key = result;          /* get following byte */
         switch (key)
         {
            case '[':
               key = get_1_byte ();
               switch (key)
               {
                  case 'A': return KEY_UP   ; break;   /* cursor keys */
                  case 'B': return KEY_DOWN ; break;
                  case 'C': return KEY_RIGHT; break;
                  case 'D': return KEY_LEFT ; break;

                  case 'H': return KEY_HOME ; break;
                  case '@': return KEY_INS  ; break;
                  case 'P': return KEY_DEL  ; break;
                  case 'Y': return KEY_END  ; break;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -