home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / l / l217 / 2.ddi / EXAMPLES / CH20EX08.PRO < prev    next >
Encoding:
Prolog Source  |  1990-03-26  |  1.2 KB  |  41 lines

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