[inherit('sys$library:starlet','lib$spawn','smgdefs','smg$repaint_line',
'BB.PEN')]
module getchar;

[global,asynchronous]function getchar:char;

{Use system routines to read one character from keyboard input in an
 The input character will be tested to see if special processing is to 
 be done.}

var
  ch : char;
  term_code : [word] 0..65535;

begin
  repeat
    smg$read_string(keyboard,ch,max_length:=1,
    		    modifiers:=io$m_cvtlow+io$m_nofiltr+io$m_noecho+io$m_purge,
		    terminator_code:=term_code);
  until term_code<>511;

  {Convert to upper case.}
  if ch in ['a'..'z'] then 
    ch := chr(ord(ch)-32);

  case term_code of
    smg$k_trm_help : getchar := key_help;
    smg$k_trm_pf2 : getchar := key_help;
    smg$k_trm_do : getchar := key_do;
    smg$k_trm_find : getchar := key_find;
    smg$k_trm_insert_here : getchar := key_insert;
    smg$k_trm_remove : getchar := key_remove;
    smg$k_trm_select : getchar := key_select;
    smg$k_trm_prev_screen : getchar := key_prev;
    smg$k_trm_next_screen : getchar := key_next;
    smg$k_trm_up : getchar := key_up;
    smg$k_trm_left : getchar := key_left;
    smg$k_trm_down : getchar := key_down;
    smg$k_trm_right : getchar := key_right;
    smg$k_trm_cr : getchar := key_cr;
    smg$k_trm_enter : getchar := key_cr;
    smg$k_trm_ctrlz : getchar := key_exit;
    otherwise
      getchar := ch
  end;  

end;
end.
