コード例 #1
0
ファイル: console.cs プロジェクト: sirmax1/coin
 public InputEvent ReadInputEvent()
 {
     var ar = new INPUT_RECORD[1];
     UInt32 dw;
     Api.Win32Check(Api.ReadConsoleInput(Handle, ar, (uint)ar.Length, out dw));
     return TranslateEvent(ar[0]);
 }
コード例 #2
0
ファイル: console.cs プロジェクト: sirmax1/coin
 public static InputEvent TranslateEvent(INPUT_RECORD ir)
 {
     switch (ir.EventType)
     {
     case EventType.KEY_EVENT:
     {
         var e = new KeyEvent() {
             KeyDown = ir.Event.KeyEvent.bKeyDown != 0,
             RepeatCount = ir.Event.KeyEvent.wRepeatCount,
             KeyCode = (Keys)ir.Event.KeyEvent.wVirtualKeyCode,
             ScanCode = ir.Event.KeyEvent.wVirtualScanCode,
             Char = (char)ir.Event.KeyEvent.uChar.AsciiChar,			//!!! Char/Unicode
             LeftAlt = (ir.Event.KeyEvent.dwControlKeyState & ControlKeyState.LEFT_ALT_PRESSED) != 0,
             RightAlt = (ir.Event.KeyEvent.dwControlKeyState & ControlKeyState.RIGHT_ALT_PRESSED) != 0,
             LeftCtrl = (ir.Event.KeyEvent.dwControlKeyState & ControlKeyState.LEFT_CTRL_PRESSED) != 0,
             RightCtrl = (ir.Event.KeyEvent.dwControlKeyState & ControlKeyState.RIGHT_CTRL_PRESSED) != 0,
             Shift = (ir.Event.KeyEvent.dwControlKeyState & ControlKeyState.SHIFT_PRESSED) != 0
         };
         return e;
     }
     case EventType.MOUSE_EVENT:
     {
         var e = new MouseEvent();
         e.X = ir.Event.MouseEvent.dwMousePosition.X;
         e.Y = ir.Event.MouseEvent.dwMousePosition.Y;
         e.Buttons = (ConMouseButtons)ir.Event.MouseEvent.dwButtonState;
         e.DoubleClick = (ir.Event.MouseEvent.dwEventFlags & 2) != 0;  //!!! Should be Sym
         return e;
     }
     case EventType.FOCUS_EVENT:
     return new FocusEvent();
     case EventType.MENU_EVENT:
     return new MenuEvent();
     case EventType.WINDOW_BUFFER_SIZE_EVENT:
     return new WindowBufferSizeEvent();
     default:
     throw new ApplicationException("Unknown EventType");
     }
 }