ConsoleKeyInfo 구조체

정의

콘솔 키로 표현된 문자와 Shift, Alt 및 Ctrl 보조키의 상태를 포함하여 누른 콘솔 키를 설명합니다.Describes the console key that was pressed, including the character represented by the console key and the state of the SHIFT, ALT, and CTRL modifier keys.

public value class ConsoleKeyInfo
[System.Serializable]
public struct ConsoleKeyInfo
type ConsoleKeyInfo = struct
Public Structure ConsoleKeyInfo
상속
ConsoleKeyInfo
특성

예제

다음 예제는 ConsoleKeyInfo 읽기 작업에서 개체입니다.The following example demonstrates using a ConsoleKeyInfo object in a read operation.

using namespace System;

void main()
{
   ConsoleKeyInfo cki;
   // Prevent example from ending if CTL+C is pressed.
   Console::TreatControlCAsInput = true;

   Console::WriteLine("Press any combination of CTL, ALT, and SHIFT, and a console key.");
   Console::WriteLine("Press the Escape (Esc) key to quit: \n");
   do 
   {
      cki = Console::ReadKey();
      Console::Write(" --- You pressed ");
      if((cki.Modifiers & ConsoleModifiers::Alt) != ConsoleModifiers()) Console::Write("ALT+");
      if((cki.Modifiers & ConsoleModifiers::Shift) != ConsoleModifiers()) Console::Write("SHIFT+");
      if((cki.Modifiers & ConsoleModifiers::Control) != ConsoleModifiers()) Console::Write("CTL+");
      Console::WriteLine(cki.Key.ToString());
   } while (cki.Key != ConsoleKey::Escape);
}
// This example displays output similar to the following:
//       Press any combination of CTL, ALT, and SHIFT, and a console key.
//       Press the Escape (Esc) key to quit:
//       
//       a --- You pressed A 
//       k --- You pressed ALT+K 
//       ► --- You pressed CTL+P 
//         --- You pressed RightArrow 
//       R --- You pressed SHIFT+R 
//                --- You pressed CTL+I 
//       j --- You pressed ALT+J 
//       O --- You pressed SHIFT+O 
//       § --- You pressed CTL+U }
using System;

class Example 
{
   public static void Main() 
   {
      ConsoleKeyInfo cki;
      // Prevent example from ending if CTL+C is pressed.
      Console.TreatControlCAsInput = true;

      Console.WriteLine("Press any combination of CTL, ALT, and SHIFT, and a console key.");
      Console.WriteLine("Press the Escape (Esc) key to quit: \n");
      do 
      {
         cki = Console.ReadKey();
         Console.Write(" --- You pressed ");
         if((cki.Modifiers & ConsoleModifiers.Alt) != 0) Console.Write("ALT+");
         if((cki.Modifiers & ConsoleModifiers.Shift) != 0) Console.Write("SHIFT+");
         if((cki.Modifiers & ConsoleModifiers.Control) != 0) Console.Write("CTL+");
         Console.WriteLine(cki.Key.ToString());
       } while (cki.Key != ConsoleKey.Escape);
    }
}
// This example displays output similar to the following:
//       Press any combination of CTL, ALT, and SHIFT, and a console key.
//       Press the Escape (Esc) key to quit:
//       
//       a --- You pressed A 
//       k --- You pressed ALT+K 
//       ► --- You pressed CTL+P 
//         --- You pressed RightArrow 
//       R --- You pressed SHIFT+R 
//                --- You pressed CTL+I 
//       j --- You pressed ALT+J 
//       O --- You pressed SHIFT+O 
//       § --- You pressed CTL+U 
Class Example
   Public Shared Sub Main()
      Dim cki As ConsoleKeyInfo
      ' Prevent example from ending if CTL+C is pressed.
      Console.TreatControlCAsInput = True

      Console.WriteLine("Press any combination of CTL, ALT, and SHIFT, and a console key.")
      Console.WriteLine("Press the Escape (Esc) key to quit: " + vbCrLf)
      Do
         cki = Console.ReadKey()
         Console.Write(" --- You pressed ")
         If (cki.Modifiers And ConsoleModifiers.Alt) <> 0 Then Console.Write("ALT+")
         If (cki.Modifiers And ConsoleModifiers.Shift) <> 0 Then Console.Write("SHIFT+")
         If (cki.Modifiers And ConsoleModifiers.Control) <> 0 Then Console.Write("CTL+")
         Console.WriteLine(cki.Key.ToString)
      Loop While cki.Key <> ConsoleKey.Escape
   End Sub 
End Class 
' This example displays output similar to the following:
'       Press any combination of CTL, ALT, and SHIFT, and a console key.
'       Press the Escape (Esc) key to quit:
'       
'       a --- You pressed A 
'       k --- You pressed ALT+K 
'       ► --- You pressed CTL+P 
'         --- You pressed RightArrow 
'       R --- You pressed SHIFT+R 
'                --- You pressed CTL+I 
'       j --- You pressed ALT+J 
'       O --- You pressed SHIFT+O 
'       § --- You pressed CTL+U 

설명

ConsoleKeyInfo 형식은 사용자가 만들 수 없습니다.The ConsoleKeyInfo type is not intended to be created by users. 호출에 대 한 응답에서 사용자에 게 반환 하는 대신는 Console.ReadKey 메서드.Instead, it is returned to the user in response to calling the Console.ReadKey method.

합니다 ConsoleKeyInfo 개체에 설명 합니다 ConsoleKey 상수 및 유니코드 문자, 있는 경우에 해당 하는 누른된 콘솔 키입니다.The ConsoleKeyInfo object describes the ConsoleKey constant and Unicode character, if any, that correspond to the pressed console key. 합니다 ConsoleKeyInfo 개체 눌렀는지의 비트 조합 ConsoleModifiers 값 하나 이상의 SHIFT, ALT 또는 CTRL 보조키를 콘솔 키를 사용 하 여 동시에 눌렀는지 여부를 합니다.The ConsoleKeyInfo object also describes, in a bitwise combination of ConsoleModifiers values, whether one or more SHIFT, ALT, or CTRL modifier keys was pressed simultaneously with the console key.

생성자

ConsoleKeyInfo(Char, ConsoleKey, Boolean, Boolean, Boolean)

지정된 문자, 콘솔 키 및 보조키를 사용하여 ConsoleKeyInfo 구조체의 새 인스턴스를 초기화합니다.Initializes a new instance of the ConsoleKeyInfo structure using the specified character, console key, and modifier keys.

속성

Key

현재 ConsoleKeyInfo 개체가 나타내는 콘솔 키를 가져옵니다.Gets the console key represented by the current ConsoleKeyInfo object.

KeyChar

현재 ConsoleKeyInfo 개체가 나타내는 유니코드 문자를 가져옵니다.Gets the Unicode character represented by the current ConsoleKeyInfo object.

Modifiers

하나 이상의 보조키를 콘솔 키와 동시에 눌렀음을 지정하는 ConsoleModifiers 값의 비트 조합을 가져옵니다.Gets a bitwise combination of ConsoleModifiers values that specifies one or more modifier keys pressed simultaneously with the console key.

메서드

Equals(ConsoleKeyInfo)

지정한 ConsoleKeyInfo 개체가 현재 ConsoleKeyInfo 개체와 같은지 여부를 나타내는 값을 가져옵니다.Gets a value indicating whether the specified ConsoleKeyInfo object is equal to the current ConsoleKeyInfo object.

Equals(Object)

지정한 개체가 현재 ConsoleKeyInfo 개체와 같은지 여부를 나타내는 값을 가져옵니다.Gets a value indicating whether the specified object is equal to the current ConsoleKeyInfo object.

GetHashCode()

현재 ConsoleKeyInfo 개체에 대한 해시 코드를 반환합니다.Returns the hash code for the current ConsoleKeyInfo object.

연산자

Equality(ConsoleKeyInfo, ConsoleKeyInfo)

지정된 ConsoleKeyInfo 개체가 같은지 여부를 나타냅니다.Indicates whether the specified ConsoleKeyInfo objects are equal.

Inequality(ConsoleKeyInfo, ConsoleKeyInfo)

지정된 ConsoleKeyInfo 개체가 같은지 여부를 나타냅니다.Indicates whether the specified ConsoleKeyInfo objects are not equal.

적용 대상

추가 정보