Advertisement
Guest User

Untitled

a guest
Oct 19th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.80 KB | None | 0 0
  1. using System;
  2.  
  3. class Example
  4. {
  5.    public static void Main()
  6.    {
  7.       ConsoleKeyInfo cki;
  8.       // Prevent example from ending if CTL+C is pressed.
  9.       Console.TreatControlCAsInput = true;
  10.  
  11.       Console.WriteLine("Press any combination of CTL, ALT, and SHIFT, and a console key.");
  12.       Console.WriteLine("Press the Escape (Esc) key to quit: \n");
  13.       do
  14.       {
  15.          cki = Console.ReadKey();
  16.          Console.Write(" --- You pressed ");
  17.          if((cki.Modifiers & ConsoleModifiers.Alt) != 0) Console.Write("ALT+");
  18.          if((cki.Modifiers & ConsoleModifiers.Shift) != 0) Console.Write("SHIFT+");
  19.          if((cki.Modifiers & ConsoleModifiers.Control) != 0) Console.Write("CTL+");
  20.          Console.WriteLine(cki.Key.ToString());
  21.        } while (cki.Key != ConsoleKey.Escape);
  22.     }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement