home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / l / l210 / 1.ddi / EXAMPLES.ARC / CH18EX08.PRO < prev    next >
Encoding:
Prolog Source  |  1988-06-21  |  1.2 KB  |  42 lines

  1. /*
  2.    Turbo Prolog 2.0 Chapter 18, Example Program 8
  3.    
  4.    Copyright (c) 1986, 88 by Borland International, Inc
  5.    
  6. */
  7.    
  8. domains
  9.    key = cr; esc; break; tab; btab; del; bdel; ins; end; home;
  10.    fkey(integer); up_arrow; down_arrow; left_arrow; right_arrow;
  11.    char(CHAR); other
  12.  
  13. predicates
  14.    readkey(key)
  15.    key_code(key, char, integer)
  16.    key_code2(key, integer)
  17.  
  18. /*
  19. goal
  20.    clearwindow,
  21.    write("Keyboard test. Press a key!"),
  22.    readkey(Key), nl,
  23.    write("The ", Key, "-key was pressed").
  24. */
  25.  
  26. clauses
  27.    readkey(Key) :-
  28.       readchar(T), char_int(T, Val), key_code(Key, T, Val).
  29.  
  30.    key_code(Key, _, 0) :- readchar(T), char_int(T, Val),
  31.    key_code2(Key, Val), !.
  32.    key_code(break, _, 3) :- !.        key_code(bdel, _, 8) :- !.
  33.    key_code(tab, _, 10) :- !.         key_code(cr, _, 13) :- !.
  34.    key_code(esc, _, 27) :- !.         key_code(char(T), T, _).
  35.    key_code2(btab, 15) :- !.          key_code2(home, 71) :- !.
  36.    key_code2(up_arrow, 72) :- !.      key_code2(left_arrow, 75):- !.
  37.    key_code2(right_arrow, 77) :- !.   key_code2(end, 79) :- !.
  38.    key_code2(down_arrow, 80) :- !.    key_code2(ins, 82) :- !.
  39.    key_code2(del, 83) :- !.
  40.    key_code2(fkey(N), V) :- V>58, V<70, N=V-58, !.
  41.    key_code2(other, _).
  42.