home *** CD-ROM | disk | FTP | other *** search
/ Power CD-ROM!! 7 / POWERCD7.ISO / prgmming / clipper / gt_alt.prg < prev    next >
Text File  |  1993-10-14  |  4KB  |  118 lines

  1. /*
  2.  File......: GT_ALT.prg
  3.  Author....: Phillip Hamlyn
  4.  BBS.......: The Dark Knight Returns
  5.  Net/Node..: 050/069
  6.  User Name.: Phillip Hamlyn
  7.  Date......: 03/03/93
  8.  Revision..: 1.0
  9.  
  10.  This is an original work by Phillip Hamlyn and is placed in the
  11.  public domain.
  12.  
  13.  Modification history:
  14.  ---------------------
  15.  
  16.  Rev 1.0 03/03/93
  17.  Initial revision.
  18. */
  19.  
  20. /*  $DOC$
  21.  *  $FUNCNAME$
  22.  *      GT_ALT()
  23.  *  $CATEGORY$
  24.  *      Keyboard
  25.  *  $ONELINER$
  26.  *      Find the real value of an ALT key combination
  27.  *  $SYNTAX$
  28.  *      GT_Alt( <cNormLetter> | <nAltInkey> ) --> <nAltInkey> | <cNormLetter>
  29.  *  $ARGUMENTS$
  30.  *      <cNormLetter> is a character that can have an ALT combination.
  31.  *      <nAltInkey>   is a key press that could be an ALT combination.
  32.  *  $RETURNS$
  33.  *      <cNormLetter> is the upper case character that relates to the
  34.  *                    passed <nAltInkey> value. Default ""
  35.  *      <nAltInkey>   is the inkey() value of the key that relates to
  36.  *                    and ALT'ified character. Perhaps the example will
  37.  *                    explain better :-). Default 0
  38.  *  $DESCRIPTION$
  39.  *      Function used to find out the real value of an ALT combination key.
  40.  *      The problem with the Inkey() function is the ALT keys are not just
  41.  *      a table offset from the 'real' keys ( like upper case and lower case
  42.  *      keys are).
  43.  *
  44.  *      This simple function will return either the character value of an
  45.  *      ALT key inkey() value, or the ALT key inkey() value of a passed
  46.  *      character.
  47.  *  $EXAMPLES$
  48.  *      GT_Alt( K_ALT_A ) --> "A"
  49.  *      GT_Alt( "A" ) --> K_ALT_A
  50.  *
  51.  *      GT_Alt( 0 ) --> ""
  52.  *      GT_Alt( "" ) --> 0
  53.  *
  54.  *      GT_Alt( K_ALT_Z ) --> "Z"
  55.  *      GT_Alt( K_ALT_C ) --> "C"
  56.  *
  57.  *      GT_Alt( "z" ) --> K_ALT_Z
  58.  *      GT_Alt( "c" ) --> K_ALT_C
  59.  *  $SEEALSO$
  60.  *
  61.  *  $INCLUDE$
  62.  *
  63.  *  $END$
  64.  */
  65.  
  66. */
  67. #INCLUDE "gt_lib.ch"
  68.  
  69. * * * * * * * *
  70. function GT_alt (xKey)
  71. * * * * * * * *
  72. local nIdx
  73. static aCompare
  74. if aCompare == NIL
  75.    aCompare  := { ;
  76.                     {"A",K_ALT_A} ,;
  77.                     {"B",K_ALT_B} ,;
  78.                     {"C",K_ALT_C} ,;
  79.                     {"D",K_ALT_D} ,;
  80.                     {"E",K_ALT_E} ,;
  81.                     {"F",K_ALT_F} ,;
  82.                     {"G",K_ALT_G} ,;
  83.                     {"H",K_ALT_H} ,;
  84.                     {"I",K_ALT_I} ,;
  85.                     {"J",K_ALT_J} ,;
  86.                     {"K",K_ALT_K} ,;
  87.                     {"L",K_ALT_L} ,;
  88.                     {"M",K_ALT_M} ,;
  89.                     {"N",K_ALT_N} ,;
  90.                     {"O",K_ALT_O} ,;
  91.                     {"P",K_ALT_P} ,;
  92.                     {"Q",K_ALT_Q} ,;
  93.                     {"R",K_ALT_R} ,;
  94.                     {"S",K_ALT_S} ,;
  95.                     {"T",K_ALT_T} ,;
  96.                     {"U",K_ALT_U} ,;
  97.                     {"V",K_ALT_V} ,;
  98.                     {"W",K_ALT_W} ,;
  99.                     {"X",K_ALT_X} ,;
  100.                     {"Y",K_ALT_Y} ,;
  101.                     {"Z",K_ALT_Z} }
  102. endif
  103. if valtype(xKey) == "N"
  104.    // weve been supplied with an ascii code of a key
  105.    if (nIdx := ascan(aCompare,{|aElem| aElem[2] == xKey} ) ) == 0
  106.       return ""
  107.    endif
  108.    // return the normal value of the key
  109.    return aCompare[nIdx,1]
  110. else
  111.    // weve been supplied with a real  key and want to know the ascii value of the Alt combination
  112.    if (nIdx := ascan(aCompare,{|aElem| aElem[1] == upper(xKey)} ) ) == 0
  113.       return 0
  114.    endif
  115.    return aCompare[nIdx,2]
  116. endif
  117. return NIL
  118.