// // Evemts.cs: Events, Key mappings // // Authors: // Miguel de Icaza (miguel@gnome.org) // using System; namespace Terminal.Gui { /// /// The Key enumeration contains special encoding for some keys, but can also /// encode all the unicode values that can be passed. /// /// /// /// If the SpecialMask is set, then the value is that of the special mask, /// otherwise, the value is the one of the lower bits (as extracted by CharMask) /// /// /// Control keys are the values between 1 and 26 corresponding to Control-A to Control-Z /// /// /// Unicode runes are also stored here, the letter 'A" for example is encoded as a value 65 (not surfaced in the enum). /// /// public enum Key : uint { /// /// Mask that indictes that this is a character value, values outside this range /// indicate special characters like Alt-key combinations or special keys on the /// keyboard like function keys, arrows keys and so on. /// CharMask = 0xfffff, /// /// If the SpecialMask is set, then the value is that of the special mask, /// otherwise, the value is the one of the lower bits (as extracted by CharMask). /// SpecialMask = 0xfff00000, /// /// The key code for the user pressing Control-spacebar /// ControlSpace = 0, /// /// The key code for the user pressing Control-A /// ControlA = 1, /// /// The key code for the user pressing Control-B /// ControlB, /// /// The key code for the user pressing Control-C /// ControlC, /// /// The key code for the user pressing Control-D /// ControlD, /// /// The key code for the user pressing Control-E /// ControlE, /// /// The key code for the user pressing Control-F /// ControlF, /// /// The key code for the user pressing Control-G /// ControlG, /// /// The key code for the user pressing Control-H /// ControlH, /// /// The key code for the user pressing Control-I (same as the tab key). /// ControlI, /// /// The key code for the user pressing the tab key (same as pressing Control-I). /// Tab = ControlI, /// /// The key code for the user pressing Control-J /// ControlJ, /// /// The key code for the user pressing Control-K /// ControlK, /// /// The key code for the user pressing Control-L /// ControlL, /// /// The key code for the user pressing Control-M /// ControlM, /// /// The key code for the user pressing Control-N (same as the return key). /// ControlN, /// /// The key code for the user pressing Control-O /// ControlO, /// /// The key code for the user pressing Control-P /// ControlP, /// /// The key code for the user pressing Control-Q /// ControlQ, /// /// The key code for the user pressing Control-R /// ControlR, /// /// The key code for the user pressing Control-S /// ControlS, /// /// The key code for the user pressing Control-T /// ControlT, /// /// The key code for the user pressing Control-U /// ControlU, /// /// The key code for the user pressing Control-V /// ControlV, /// /// The key code for the user pressing Control-W /// ControlW, /// /// The key code for the user pressing Control-X /// ControlX, /// /// The key code for the user pressing Control-Y /// ControlY, /// /// The key code for the user pressing Control-Z /// ControlZ, /// /// The key code for the user pressing the escape key /// Esc = 27, /// /// The key code for the user pressing the return key. /// Enter = '\n', /// /// The key code for the user pressing the space bar /// Space = 32, /// /// The key code for the user pressing the delete key. /// Delete = 127, /// /// When this value is set, the Key encodes the sequence Alt-KeyValue. /// And the actual value must be extracted by removing the AltMask. /// AltMask = 0x80000000, /// /// When this value is set, the Key encodes the sequence Ctrl-KeyValue. /// And the actual value must be extracted by removing the CtrlMask. /// CtrlMask = 0x40000000, /// /// Backspace key. /// Backspace = 0x100000, /// /// Cursor up key /// CursorUp, /// /// Cursor down key. /// CursorDown, /// /// Cursor left key. /// CursorLeft, /// /// Cursor right key. /// CursorRight, /// /// Page Up key. /// PageUp, /// /// Page Down key. /// PageDown, /// /// Home key /// Home, /// /// End key /// End, /// /// Delete character key /// DeleteChar, /// /// Insert character key /// InsertChar, /// /// F1 key. /// F1, /// /// F2 key. /// F2, /// /// F3 key. /// F3, /// /// F4 key. /// F4, /// /// F5 key. /// F5, /// /// F6 key. /// F6, /// /// F7 key. /// F7, /// /// F8 key. /// F8, /// /// F9 key. /// F9, /// /// F10 key. /// F10, /// /// Shift-tab key (backwards tab key). /// BackTab, /// /// A key with an unknown mapping was raised. /// Unknown } /// /// Describes a keyboard event. /// public struct KeyEvent { /// /// Symb olid definition for the key. /// public Key Key; /// /// The key value cast to an integer, you will typicall use this for /// extracting the Unicode rune value out of a key, when none of the /// symbolic options are in use. /// public int KeyValue => (int)Key; /// /// Gets a value indicating whether the Alt key was pressed (real or synthesized) /// /// true if is alternate; otherwise, false. public bool IsAlt => (Key & Key.AltMask) != 0; /// /// Determines whether the value is a control key (and NOT just the ctrl key) /// /// true if is ctrl; otherwise, false. public bool IsCtrl => ((uint)Key >= 1) && ((uint)Key <= 26); /// /// Constructs a new KeyEvent from the provided Key value - can be a rune cast into a Key value /// public KeyEvent (Key k) { Key = k; } } /// /// Mouse flags reported in MouseEvent. /// /// /// They just happen to map to the ncurses ones. /// [Flags] public enum MouseFlags { /// /// The first mouse button was pressed. /// Button1Pressed = unchecked((int)0x2), /// /// The first mouse button was released. /// Button1Released = unchecked((int)0x1), /// /// The first mouse button was clicked (press+release). /// Button1Clicked = unchecked((int)0x4), /// /// The first mouse button was double-clicked. /// Button1DoubleClicked = unchecked((int)0x8), /// /// The first mouse button was triple-clicked. /// Button1TripleClicked = unchecked((int)0x10), /// /// The second mouse button was pressed. /// Button2Pressed = unchecked((int)0x80), /// /// The second mouse button was released. /// Button2Released = unchecked((int)0x40), /// /// The second mouse button was clicked (press+release). /// Button2Clicked = unchecked((int)0x100), /// /// The second mouse button was double-clicked. /// Button2DoubleClicked = unchecked((int)0x200), /// /// The second mouse button was triple-clicked. /// Button2TripleClicked = unchecked((int)0x400), /// /// The third mouse button was pressed. /// Button3Pressed = unchecked((int)0x2000), /// /// The third mouse button was released. /// Button3Released = unchecked((int)0x1000), /// /// The third mouse button was clicked (press+release). /// Button3Clicked = unchecked((int)0x4000), /// /// The third mouse button was double-clicked. /// Button3DoubleClicked = unchecked((int)0x8000), /// /// The third mouse button was triple-clicked. /// Button3TripleClicked = unchecked((int)0x10000), /// /// The fourth mouse button was pressed. /// Button4Pressed = unchecked((int)0x80000), /// /// The fourth mouse button was released. /// Button4Released = unchecked((int)0x40000), /// /// The fourth button was clicked (press+release). /// Button4Clicked = unchecked((int)0x100000), /// /// The fourth button was double-clicked. /// Button4DoubleClicked = unchecked((int)0x200000), /// /// The fourth button was triple-clicked. /// Button4TripleClicked = unchecked((int)0x400000), /// /// Flag: the shift key was pressed when the mouse button took place. /// ButtonShift = unchecked((int)0x2000000), /// /// Flag: the ctrl key was pressed when the mouse button took place. /// ButtonCtrl = unchecked((int)0x1000000), /// /// Flag: the alt key was pressed when the mouse button took place. /// ButtonAlt = unchecked((int)0x4000000), /// /// The mouse position is being reported in this event. /// ReportMousePosition = unchecked((int)0x8000000), /// /// Vertical button wheeled up. /// WheeledUp = unchecked((int)0x10000000), /// /// Vertical button wheeled up. /// WheeledDown = unchecked((int)0x20000000), /// /// Mask that captures all the events. /// AllEvents = unchecked((int)0x7ffffff), } /// /// Describes a mouse event /// public struct MouseEvent { /// /// The X (column) location for the mouse event. /// public int X; /// /// The Y (column) location for the mouse event. /// public int Y; /// /// Flags indicating the kind of mouse event that is being posted. /// public MouseFlags Flags; /// /// The offset X (column) location for the mouse event. /// public int OfX; /// /// The offset Y (column) location for the mouse event. /// public int OfY; /// /// The current view at the location for the mouse event. /// public View View; /// /// Returns a that represents the current . /// /// A that represents the current . public override string ToString() { return $"({X},{Y}:{Flags}"; } } }