2016-07-06 41 views
1

在Windows上,Eiffel中是否存在類似Console.ReadKey的問題?在埃菲爾控制檯應用程序中讀取密鑰

我需要一種方式來從控制檯讀取輸入,而無需等待用戶按Enter鍵。

功能io.read_character無法使用,因爲它會阻止,直到用戶按Enter鍵。

回答

1

正如在SO(herehere)以及elsewhere的回答中所解釋的那樣,沒有便攜式方式從控制檯讀取角色而無需等待。但是,您可以通過連接到Eiffel的外部代碼輕鬆使用鏈接中列出的任何方法。下面的例子演示瞭如何做到這一點在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: CHARACTER 
     -- Read a character from a console without waiting for Enter. 
    external "C inline use <conio.h>" 
     alias "return getch();" 
    end 

,那麼該功能read_char可以從你的代碼作爲一個經常一個被稱爲

相關問題