2016-07-06 2 views
1

에펠의 Windows에서 Console.ReadKey과 같은 것이 있습니까?Eiffel 콘솔 응용 프로그램에서 키 읽기

사용자가 Enter 키를 누르지 않고 콘솔에서 입력을 읽는 방법이 필요합니다.

기능이 인 경우 사용자가 Enter 키를 누를 때까지 차단되기 때문에 사용할 수 없습니다.

답변

1

elsewhere뿐만 아니라 SO (here 또는 here)에 대한 응답에서 설명한 것처럼 대기없이 콘솔에서 문자를 읽을 수있는 이식성이 없습니다. 그러나 에펠의 외부 코드와 인터페이스하여 링크에 나열된 방법 중 하나를 쉽게 사용할 수 있습니다. 다음 예는 Windows에서이 작업을 수행하는 방법을 보여줍니다

 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 
: 그런 기능 read_char 정기적 하나로서 사용자 코드에서

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

를 호출 할 수 있습니다

관련 문제