2016-09-25 85 views
-4

林trinying通過按下(Ctrl + C)來寫一個字,但不工作錯誤cs1001不能使用命令CTRLç

請幫我

請給我一個手

using System; 

      using System.Runtime.InteropServices; 

    class MainClass 

     { 
static void Main() 
    { 
     ConsoleKeyInfo keypress; 
    keypress = Console.ReadKey(); // read keystrokes 

    if (keypress.Key == ConsoleKey.(CTRL-C)) 
    { 
    Console.Write("One "); 


} 
} 
    }  
+0

請幫助我。不能使用這個句子if(keypress.Key == ConsoleKey。(CTRL-C)) – jhonny625

回答

1

控制檯應用程序考慮CTRL + C是「終止命令」,其中的終止命令預計會停止應用程序的功能並迫使它關閉。使用Ctrl + C作爲輸入的密鑰是錯誤的開始與...

無論其...

的keypress.Key應該是C鍵,然後你還需要檢查是否有任何「修飾」是按下。 ALT,SHIFT,CTRL是主要的修飾鍵,你通常檢查一個布爾值來查看它們是否被按下。 。所以你的應用程序會檢查C鍵是否被按下,並且CTRL修飾符是否被按下。

檢查了這一點,以獲得更多信息: How to determine which key modifier is pressed