Advertisement
obernardovieira

Basic Get Key Pressed

Jun 2nd, 2013
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.98 KB | None | 0 0
  1. //by MSDN - Microsoft
  2.  
  3. #include <iostream>
  4.  
  5. #using <mscorlib.dll>
  6.  
  7. using namespace System;
  8.  
  9. int main()
  10. {
  11.    ConsoleKeyInfo cki;
  12.    // Prevent example from ending if CTL+C is pressed.
  13.    Console::TreatControlCAsInput = true;
  14.  
  15.    Console::WriteLine("Press any combination of CTL, ALT, and SHIFT, and a console key.");
  16.    Console::WriteLine("Press the Escape (Esc) key to quit: \n");
  17.    do
  18.    {
  19.       cki = Console::ReadKey();
  20.       Console::Write(" --- You pressed ");
  21.       if((cki.Modifiers & ConsoleModifiers::Alt) != ConsoleModifiers()) Console::Write("ALT+");
  22.       if((cki.Modifiers & ConsoleModifiers::Shift) != ConsoleModifiers()) Console::Write("SHIFT+");
  23.       if((cki.Modifiers & ConsoleModifiers::Control) != ConsoleModifiers()) Console::Write("CTL+");
  24.       Console::WriteLine(cki.Key.ToString());
  25.    } while (cki.Key != ConsoleKey::Escape);
  26.    return 0;
  27. }
  28. //se der erro /clr so ir em Configuration Properties -> General -> Common Language Runtime Support e marcar /clr
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement