using System;

public class 키보드입력
{
    public static void Main()
    {
        Console.WriteLine("아무키나 누르세요.");
        // 키보드 키 값 입력
        ConsoleKeyInfo cki = Console.ReadKey(true); // ConsoleKeyInfo : 구조체
        Console.WriteLine("{0}", cki.Key); // 키
        Console.WriteLine("{0}", cki.KeyChar); // 유니코드
        Console.WriteLine("{0}", cki.Modifiers); // Ctrl, Shift, Alt조합
        if (cki.Key == ConsoleKey.Q) // ConsoleKey : 열거형
        {
            Console.WriteLine("Q를 입력하셨군요...");
        }
    }
}


=======================================================================================

교재 75p ReadKey 예제


using System;

public class ReadKey예제
{
    public static void Main()
    {
        ConsoleKeyInfo cki; // 구조체
        int x = 40, y = 12;
        for (; ; )
        {
            Console.Clear(); // 화면을 지운다.
            Console.SetCursorPosition(x, y); //커서 좌표값 재설정 (40, 12)
            Console.Write('#'); // 커서가 있는 (40, 12) 위치에 #을 표시
            cki = Console.ReadKey(true); //키 자체를 입력 받는다. true : 화면에 다시출력 안함
            switch (cki.Key)
            {
                case ConsoleKey.LeftArrow: // 열거형
                    x--;
                    break;
                case ConsoleKey.RightArrow:
                    x++;
                    break;
                case ConsoleKey.UpArrow:
                    y--;
                    break;
                case ConsoleKey.DownArrow:
                    y++;
                    break;
                case ConsoleKey.Q:
                    return;
            }
        }
    }
}


'.NET프로그래밍 > C# 3.5 SP1' 카테고리의 다른 글

8. 이스케이프시퀀스  (0) 2009.08.04
7. 콘솔멤버(ConsolMember)  (0) 2009.08.04
5. 자리표시자  (0) 2009.08.04
4. 기본입출력문  (0) 2009.08.04
3. C# 기본구조  (0) 2009.08.04
Posted by holland14
: