home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / MODEM / UWPC201.ZIP / UW-SRC.ZIP / KEYS.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-03  |  4.6 KB  |  137 lines

  1. /*-------------------------------------------------------------------------
  2.  
  3.   KEYS.CPP - Declarations for the keyboard handling for Unix Windows.
  4.  
  5.     This file is part of UW/PC - a multi-window comms package for the PC.
  6.     Copyright (C) 1990-1991  Rhys Weatherley
  7.  
  8.     This program is free software; you can redistribute it and/or modify
  9.     it under the terms of the GNU General Public License as published by
  10.     the Free Software Foundation; either version 1, or (at your option)
  11.     any later version.
  12.  
  13.     This program is distributed in the hope that it will be useful,
  14.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.     GNU General Public License for more details.
  17.  
  18.     You should have received a copy of the GNU General Public License
  19.     along with this program; if not, write to the Free Software
  20.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  
  22.   Revision History:
  23.   ================
  24.  
  25.    Version  DD/MM/YY  By  Description
  26.    -------  --------  --  ----------------------------------------------
  27.      1.0    20/12/90  RW  Original Version of KEYS.CPP
  28.      1.1    01/01/91  RW  Clean up and remove __PROTO__
  29.      1.2    01/01/91  RW  Add trapping of INT 1B to disable CTRL-BREAK
  30.      1.3    23/01/91  RW  Convert to C++ for Version 2.00 of UW/PC.
  31.      1.4    05/05/91  RW  Process function key expansions.
  32.  
  33.   You may contact the author by:
  34.   =============================
  35.  
  36.    e-mail: rhys@cs.uq.oz.au
  37.      mail: Rhys Weatherley
  38.        5 Horizon Drive
  39.        Jamboree Heights
  40.        Queensland 4074
  41.        Australia
  42.  
  43. -------------------------------------------------------------------------*/
  44.  
  45. #include "keys.h"        /* Declarations for this module */
  46. #include "config.h"        /* Configuration routines for UW/PC */
  47. #include <bios.h>        /* Turbo C/C++ BIOS handling routines */
  48. #include <dos.h>        /* DOS/Interrupt handling routines */
  49. #include <ctype.h>        /* Character typing macros */
  50.  
  51. /*
  52.  * Global declarations for function key expansions.
  53.  */
  54. static    char    *ExpandKey;
  55. static    int    AltKeys[26] =
  56.       {0x1E00,0x3000,0x2E00,0x2000,0x1200,0x2100,0x2200,0x2300,
  57.        0x1700,0x2400,0x2500,0x2600,0x3200,0x3100,0x1800,0x1900,
  58.        0x1000,0x1300,0x1F00,0x1400,0x1600,0x2F00,0x1100,0x2D00,
  59.        0x1500,0x2C00};
  60. #define    FIRST_DIGIT    0x7800
  61.  
  62. /* Define the saved interrupt address for INT 1B */
  63. static    void    interrupt (far *saveint) (...);
  64.  
  65. /* Interrupt routine to ignore the BREAK routine */
  66. static    void    interrupt IgnoreBreak (...)
  67. {
  68.   /* Don't do anything - want to ignore the BREAK */
  69. } /* IgnoreBreak */
  70.  
  71. /* Initialise the keyboard handling system */
  72. void    InitKeyboard (void)
  73. {
  74.   saveint = getvect (0x1B);
  75.   setvect (0x1B,IgnoreBreak);
  76.   ExpandKey = 0;
  77. } /* InitKeyboard */
  78.  
  79. /* Terminate the keyboard handling system */
  80. void    TermKeyboard (void)
  81. {
  82.   setvect (0x1B,saveint);
  83. } /* TermKeyboard */
  84.  
  85. /* Return the user's next keypress, or -1 if none available */
  86. /* Returns 0-255 for the ASCII values, or extended keycode. */
  87. int    GetKeyPress (void)
  88. {
  89.   int key;
  90.   while (1)
  91.     {
  92.       if (ExpandKey)
  93.         {
  94.       switch (*ExpandKey)
  95.         {
  96.           case '\0':break;    /* At end of expansion */
  97.           case '~':    ++ExpandKey;
  98.                   return (PAUSE_KEY);
  99.           case '^':    ++ExpandKey;
  100.                   if (*ExpandKey)
  101.               return ((*ExpandKey++) & 0x1F);
  102.             break;
  103.           case '#':    ++ExpandKey;
  104.                   if (isdigit (*ExpandKey) && *ExpandKey != '0')
  105.               return (FIRST_DIGIT + (((*ExpandKey++) - '1') << 8));
  106.              else if (isalpha (*ExpandKey))
  107.               return (AltKeys[((*ExpandKey++) & 0xDF) - 'A']);
  108.              else if (*ExpandKey)
  109.               return (*ExpandKey++);
  110.             break;
  111.           default:    return (*ExpandKey++);
  112.         }
  113.           ExpandKey = 0;    /* Function key expansion is finished */
  114.     }
  115.       if (!bioskey (1))
  116.         return (-1);        /* There are no keys ready */
  117.       key = bioskey (0);
  118.       if (key & 255)        /* Normal ASCII keystroke */
  119.         return (key & 255);
  120.        else if (key == 0x300)    /* CTRL-@ */
  121.         return (0);
  122.        else if (key == 0)    /* CTRL-BREAK */
  123.         return (BREAK_KEY);
  124.        else if (key == 0x7500)    /* CTRL-END */
  125.         return (BREAK_KEY);
  126.        else if (key == 0x8100)    /* ALT-0 -> ALT-W */
  127.         return (NEXTWIN_KEY);
  128.        else if (key == 0x5300)
  129.         return (0x7F);        /* Delete key => ASCII 'DEL' character */
  130.        else if (key >= 0x3B00 && key <= 0x4400 &&
  131.                UWConfig.FKeys[(key >> 8) - 0x3B][0] != '\0')
  132.         ExpandKey = UWConfig.FKeys[(key >> 8) - 0x3B];
  133.        else
  134.         return (key);        /* Return extended keycode direct */
  135.     }
  136. } /* GetKeyPress */
  137.