2016-07-06 4 views

答えて

1

SO(hereまたはhere)およびelsewhereの回答で説明されているように、待機せずにコンソールから文字を読み込むための移植可能な方法はありません。ただし、リンクに記載されている方法のいずれかを、Eiffelの外部コードとのインタフェースで簡単に使用できます。次の例では、Windows上でそれを行う方法を示します。

read_char: CHARACTER 
     -- Read a character from a console without waiting for Enter. 
    external "C inline use <conio.h>" 
     alias "return getch();" 
    end 

次に機能read_charは、通常の一人として、あなたのコードから呼び出すことができます。

 from 
      io.put_string ("Press q or Esc to exit.") 
      io.put_new_line 
     until 
      c = 'q' or c = '%/27/' 
     loop 
      c := read_char 
      io.put_string ("You pressed: ") 
      if c = '%U' or c = '%/224/' then 
        -- Extended key is pressed, read next character. 
       c := read_char 
       io.put_string ("extended key ") 
       io.put_natural_32 (c.natural_32_code) 
      else 
       io.put_character (c) 
      end 
      io.put_new_line 
     end 
関連する問題