From 88a00658dbcb53306d56af1b766594c0eea10b2c Mon Sep 17 00:00:00 2001 From: Tig Kindel Date: Fri, 20 Oct 2023 14:55:24 -0600 Subject: [PATCH] Refactored KeyEvent and KeyEventEventArgs into a single class --- Terminal.Gui/Application.cs | 37 +- Terminal.Gui/ConsoleDrivers/ConsoleDriver.cs | 12 +- .../CursesDriver/CursesDriver.cs | 50 +- .../ConsoleDrivers/FakeDriver/FakeDriver.cs | 10 +- Terminal.Gui/ConsoleDrivers/NetDriver.cs | 10 +- Terminal.Gui/ConsoleDrivers/WindowsDriver.cs | 28 +- Terminal.Gui/Input/KeyEventEventArgs.cs | 24 - Terminal.Gui/Input/{Event.cs => Keyboard.cs} | 249 +--- Terminal.Gui/Input/Mouse.cs | 186 +++ Terminal.Gui/Input/Responder.cs | 77 +- Terminal.Gui/Input/ShortcutHelper.cs | 4 +- .../Text/Autocomplete/AppendAutocomplete.cs | 2 +- .../Text/Autocomplete/AutocompleteBase.cs | 2 +- .../Text/Autocomplete/IAutocomplete.cs | 2 +- .../Text/Autocomplete/PopupAutocomplete.cs | 4 +- Terminal.Gui/Text/CollectionNavigatorBase.cs | 2 +- Terminal.Gui/View/ViewKeyboard.cs | 91 +- Terminal.Gui/Views/Button.cs | 14 +- Terminal.Gui/Views/CheckBox.cs | 8 +- Terminal.Gui/Views/ColorPicker.cs | 4 +- Terminal.Gui/Views/ComboBox.cs | 6 +- Terminal.Gui/Views/DateField.cs | 8 +- Terminal.Gui/Views/Dialog.cs | 6 +- Terminal.Gui/Views/FileDialog.cs | 34 +- Terminal.Gui/Views/GraphView/GraphView.cs | 4 +- Terminal.Gui/Views/HexView.cs | 2 +- Terminal.Gui/Views/Label.cs | 2 +- Terminal.Gui/Views/ListView.cs | 4 +- Terminal.Gui/Views/Menu.cs | 22 +- Terminal.Gui/Views/RadioGroup.cs | 6 +- Terminal.Gui/Views/ScrollView.cs | 6 +- Terminal.Gui/Views/Slider.cs | 6 +- Terminal.Gui/Views/StatusBar.cs | 2 +- Terminal.Gui/Views/TabView.cs | 6 +- Terminal.Gui/Views/TableView/TableView.cs | 16 +- .../Views/TableView/TreeTableSource.cs | 6 +- Terminal.Gui/Views/TextField.cs | 16 +- Terminal.Gui/Views/TextValidateField.cs | 2 +- Terminal.Gui/Views/TextView.cs | 12 +- Terminal.Gui/Views/TileView.cs | 8 +- Terminal.Gui/Views/TimeField.cs | 2 +- Terminal.Gui/Views/Toplevel.cs | 16 +- Terminal.Gui/Views/TreeView/TreeView.cs | 10 +- Terminal.Gui/Views/Wizard/Wizard.cs | 10 +- UICatalog/KeyBindingsDialog.cs | 2 +- UICatalog/Scenarios/ASCIICustomButton.cs | 12 +- .../Scenarios/BackgroundWorkerCollection.cs | 2 +- UICatalog/Scenarios/ContextMenus.cs | 2 +- UICatalog/Scenarios/CsvEditor.cs | 4 +- UICatalog/Scenarios/DynamicMenuBar.cs | 8 +- UICatalog/Scenarios/DynamicStatusBar.cs | 8 +- UICatalog/Scenarios/Editor.cs | 8 +- UICatalog/Scenarios/InteractiveTree.cs | 4 +- UICatalog/Scenarios/Keys.cs | 53 +- UICatalog/Scenarios/LineDrawing.cs | 6 +- UICatalog/Scenarios/ListColumns.cs | 4 +- UICatalog/Scenarios/SendKeys.cs | 10 +- UICatalog/Scenarios/SingleBackgroundWorker.cs | 2 +- UICatalog/Scenarios/Snake.cs | 2 +- UICatalog/Scenarios/TableEditor.cs | 4 +- UICatalog/Scenarios/TreeViewFileSystem.cs | 4 +- UICatalog/Scenarios/VkeyPacketSimulator.cs | 39 +- UICatalog/UICatalog.cs | 12 +- UnitTests/Application/ApplicationTests.cs | 62 +- UnitTests/Application/MainLoopTests.cs | 4 +- .../ConsoleDrivers/ConsoleDriverTests.cs | 8 +- UnitTests/ConsoleDrivers/KeyTests.cs | 2 +- UnitTests/Dialogs/DialogTests.cs | 8 +- UnitTests/Input/ResponderTests.cs | 12 +- UnitTests/Text/AutocompleteTests.cs | 34 +- UnitTests/Text/CollectionNavigatorTests.cs | 4 +- UnitTests/UICatalog/ScenarioTests.cs | 10 +- UnitTests/View/KeyboardTests.cs | 30 +- UnitTests/View/Layout/DimTests.cs | 20 +- UnitTests/View/Layout/PosTests.cs | 8 +- UnitTests/View/NavigationTests.cs | 48 +- UnitTests/View/ViewTests.cs | 16 +- UnitTests/Views/AllViewsTests.cs | 6 +- UnitTests/Views/AppendAutocompleteTests.cs | 10 +- UnitTests/Views/ButtonTests.cs | 26 +- UnitTests/Views/CheckBoxTests.cs | 14 +- UnitTests/Views/ColorPickerTests.cs | 12 +- UnitTests/Views/ComboBoxTests.cs | 126 +- UnitTests/Views/ContextMenuTests.cs | 16 +- UnitTests/Views/DateFieldTests.cs | 26 +- UnitTests/Views/HexViewTests.cs | 114 +- UnitTests/Views/ListViewTests.cs | 36 +- UnitTests/Views/MenuTests.cs | 210 ++-- UnitTests/Views/RadioGroupTests.cs | 20 +- UnitTests/Views/ScrollViewTests.cs | 130 +-- UnitTests/Views/StatusBarTests.cs | 4 +- UnitTests/Views/TableViewTests.cs | 186 +-- UnitTests/Views/TextFieldTests.cs | 200 ++-- UnitTests/Views/TextValidateFieldTests.cs | 110 +- UnitTests/Views/TextViewTests.cs | 1036 ++++++++--------- UnitTests/Views/TileViewTests.cs | 70 +- UnitTests/Views/TimeFieldTests.cs | 26 +- UnitTests/Views/ToplevelTests.cs | 110 +- UnitTests/Views/TreeTableSourceTests.cs | 32 +- UnitTests/Views/TreeViewTests.cs | 14 +- UnitTests/Views/WindowTests.cs | 2 +- 101 files changed, 1998 insertions(+), 2018 deletions(-) delete mode 100644 Terminal.Gui/Input/KeyEventEventArgs.cs rename Terminal.Gui/Input/{Event.cs => Keyboard.cs} (65%) create mode 100644 Terminal.Gui/Input/Mouse.cs diff --git a/Terminal.Gui/Application.cs b/Terminal.Gui/Application.cs index b1bcc63fda..57d9f50225 100644 --- a/Terminal.Gui/Application.cs +++ b/Terminal.Gui/Application.cs @@ -94,7 +94,7 @@ private static List GetSupportedCultures () #region Initialization (Init/Shutdown) /// - /// Initializes a new instance of Application. + /// Initializes a new instance of a Application. /// /// /// Call this method once per instance (or after has been called). @@ -1064,7 +1064,6 @@ public static void GrabMouse (View view) if (!OnGrabbingMouse (view)) { OnGrabbedMouse (view); _mouseGrabView = view; - //Driver.UncookMouse (); } } @@ -1121,8 +1120,8 @@ static void OnUnGrabbedMouse (View view) /// /// /// - /// Use this event to receive mouse events in screen coordinates. Use to receive - /// mouse events relative to a 's bounds. + /// Use this event to receive all mouse events in screen coordinates. Use to receive + /// mouse events specific to a 's bounds. /// /// /// The will contain the that contains the mouse coordinates. @@ -1279,7 +1278,7 @@ static void OnAlternateBackwardKeyChanged (KeyChangedEventArgs oldKey) static Key _quitKey = Key.Q | Key.CtrlMask; /// - /// Gets or sets the key to quit the application. + /// Gets or sets the key to quit the application. The default is Ctrl-Q. /// [SerializableConfigurationProperty (Scope = typeof (SettingsScope)), JsonConverter (typeof (KeyJsonConverter))] public static Key QuitKey { @@ -1302,13 +1301,17 @@ static void OnQuitKeyChanged (KeyChangedEventArgs e) /// /// Event fired after a key has been pressed and released. - /// Set to to suppress the event. + /// Set to to suppress the event. /// + /// . /// + /// + /// + /// /// All drivers support firing the event. Some drivers (Curses) /// do not support firing the and events. /// - public static event EventHandler KeyPressed; + public static event EventHandler KeyPressed; /// /// Called after a key has been pressed and released. Fires the event. @@ -1319,7 +1322,7 @@ static void OnQuitKeyChanged (KeyChangedEventArgs e) /// /// /// if the key was handled. - public static bool OnKeyPressed (KeyEventEventArgs a) + public static bool OnKeyPressed (KeyEventArgs a) { KeyPressed?.Invoke (null, a); if (a.Handled) { @@ -1328,7 +1331,7 @@ public static bool OnKeyPressed (KeyEventEventArgs a) var chain = _topLevels.ToList (); foreach (var topLevel in chain) { - if (topLevel.ProcessHotKey (a.KeyEvent)) { + if (topLevel.ProcessHotKey (a)) { return true; } if (topLevel.Modal) @@ -1336,7 +1339,7 @@ public static bool OnKeyPressed (KeyEventEventArgs a) } foreach (var topLevel in chain) { - if (topLevel.ProcessKey (a.KeyEvent)) { + if (topLevel.OnKeyPressed (a)) { return true; } if (topLevel.Modal) @@ -1345,7 +1348,7 @@ public static bool OnKeyPressed (KeyEventEventArgs a) foreach (var topLevel in chain) { // Process the key normally - if (topLevel.ProcessColdKey (a.KeyEvent)) { + if (topLevel.ProcessColdKey (a)) { return true; } if (topLevel.Modal) @@ -1361,18 +1364,18 @@ public static bool OnKeyPressed (KeyEventEventArgs a) /// All drivers support firing the event. Some drivers (Curses) /// do not support firing the and events. /// - public static event EventHandler KeyDown; + public static event EventHandler KeyDown; /// /// Called when a key is pressed (and not yet released). Fires the event. /// /// - public static void OnKeyDown (KeyEventEventArgs a) + public static void OnKeyDown (KeyEventArgs a) { KeyDown?.Invoke (null, a); var chain = _topLevels.ToList (); foreach (var topLevel in chain) { - if (topLevel.OnKeyDown (a.KeyEvent)) + if (topLevel.OnKeyDown (a)) return; if (topLevel.Modal) break; @@ -1386,18 +1389,18 @@ public static void OnKeyDown (KeyEventEventArgs a) /// All drivers support firing the event. Some drivers (Curses) /// do not support firing the and events. /// - public static event EventHandler KeyUp; + public static event EventHandler KeyUp; /// /// Called when a key is released. Fires the event. /// /// - public static void OnKeyUp (KeyEventEventArgs a) + public static void OnKeyUp (KeyEventArgs a) { KeyUp?.Invoke (null, a); var chain = _topLevels.ToList (); foreach (var topLevel in chain) { - if (topLevel.OnKeyUp (a.KeyEvent)) + if (topLevel.OnKeyUp (a)) return; if (topLevel.Modal) break; diff --git a/Terminal.Gui/ConsoleDrivers/ConsoleDriver.cs b/Terminal.Gui/ConsoleDrivers/ConsoleDriver.cs index 042a10bb24..d3150d0f7e 100644 --- a/Terminal.Gui/ConsoleDrivers/ConsoleDriver.cs +++ b/Terminal.Gui/ConsoleDrivers/ConsoleDriver.cs @@ -447,35 +447,35 @@ public virtual Attribute MakeColor (Color foreground, Color background) /// /// Event fired after a key has been pressed and released. /// - public event EventHandler KeyPressed; + public event EventHandler KeyPressed; /// /// Called after a key has been pressed and released. Fires the event. /// /// - public void OnKeyPressed (KeyEventEventArgs a) => KeyPressed?.Invoke(this, a); + public void OnKeyPressed (KeyEventArgs a) => KeyPressed?.Invoke(this, a); /// /// Event fired when a key is released. /// - public event EventHandler KeyUp; + public event EventHandler KeyUp; /// /// Called when a key is released. Fires the event. /// /// - public void OnKeyUp (KeyEventEventArgs a) => KeyUp?.Invoke (this, a); + public void OnKeyUp (KeyEventArgs a) => KeyUp?.Invoke (this, a); /// /// Event fired when a key is pressed. /// - public event EventHandler KeyDown; + public event EventHandler KeyDown; /// /// Called when a key is pressed. Fires the event. /// /// - public void OnKeyDown (KeyEventEventArgs a) => KeyDown?.Invoke (this, a); + public void OnKeyDown (KeyEventArgs a) => KeyDown?.Invoke (this, a); /// /// Event fired when a mouse event occurs. diff --git a/Terminal.Gui/ConsoleDrivers/CursesDriver/CursesDriver.cs b/Terminal.Gui/ConsoleDrivers/CursesDriver/CursesDriver.cs index 036c201783..8cc537b351 100644 --- a/Terminal.Gui/ConsoleDrivers/CursesDriver/CursesDriver.cs +++ b/Terminal.Gui/ConsoleDrivers/CursesDriver/CursesDriver.cs @@ -458,7 +458,7 @@ internal void ProcessInput () int wch2 = wch; while (wch2 == Curses.KeyMouse) { - KeyEvent key = null; + KeyEventArgs key = null; ConsoleKeyInfo [] cki = new ConsoleKeyInfo [] { new ConsoleKeyInfo ((char)Key.Esc, 0, false, false, false), new ConsoleKeyInfo ('[', 0, false, false, false), @@ -491,9 +491,9 @@ internal void ProcessInput () wch -= 60; k = Key.ShiftMask | Key.AltMask | MapCursesKey (wch); } - OnKeyDown (new KeyEventEventArgs (new KeyEvent (k, MapKeyModifiers (k)))); - OnKeyUp (new KeyEventEventArgs (new KeyEvent (k, MapKeyModifiers (k)))); - OnKeyPressed (new KeyEventEventArgs (new KeyEvent (k, MapKeyModifiers (k)))); + OnKeyDown (new KeyEventArgs (k, MapKeyModifiers (k))); + OnKeyUp (new KeyEventArgs (k, MapKeyModifiers (k))); + OnKeyPressed (new KeyEventArgs (k, MapKeyModifiers (k))); return; } @@ -507,7 +507,7 @@ internal void ProcessInput () k = Key.AltMask | MapCursesKey (wch); } if (code == 0) { - KeyEvent key = null; + KeyEventArgs key = null; // The ESC-number handling, debatable. // Simulates the AltMask itself by pressing Alt + Space. @@ -543,19 +543,19 @@ internal void ProcessInput () k = (Key)((uint)(Key.AltMask | Key.CtrlMask) + wch2); } } - key = new KeyEvent (k, MapKeyModifiers (k)); - OnKeyDown (new KeyEventEventArgs (key)); - OnKeyUp (new KeyEventEventArgs (key)); - OnKeyPressed (new KeyEventEventArgs (key)); + key = new KeyEventArgs (k, MapKeyModifiers (k)); + OnKeyDown (key); + OnKeyUp (key); + OnKeyPressed (key); } else { k = Key.Esc; - OnKeyPressed (new KeyEventEventArgs (new KeyEvent (k, MapKeyModifiers (k)))); + OnKeyPressed (new KeyEventArgs (k, MapKeyModifiers (k))); } } else if (wch == Curses.KeyTab) { k = MapCursesKey (wch); - OnKeyDown (new KeyEventEventArgs (new KeyEvent (k, MapKeyModifiers (k)))); - OnKeyUp (new KeyEventEventArgs (new KeyEvent (k, MapKeyModifiers (k)))); - OnKeyPressed (new KeyEventEventArgs (new KeyEvent (k, MapKeyModifiers (k)))); + OnKeyDown (new KeyEventArgs (k, MapKeyModifiers (k))); + OnKeyUp (new KeyEventArgs (k, MapKeyModifiers (k))); + OnKeyPressed (new KeyEventArgs (k, MapKeyModifiers (k))); } else { // Unfortunately there are no way to differentiate Ctrl+alfa and Ctrl+Shift+alfa. k = (Key)wch; @@ -568,21 +568,21 @@ internal void ProcessInput () } else if (wch >= (uint)Key.A && wch <= (uint)Key.Z) { _keyModifiers.Shift = true; } - OnKeyDown (new KeyEventEventArgs (new KeyEvent (k, MapKeyModifiers (k)))); - OnKeyUp (new KeyEventEventArgs (new KeyEvent (k, MapKeyModifiers (k)))); - OnKeyPressed (new KeyEventEventArgs (new KeyEvent (k, MapKeyModifiers (k)))); + OnKeyDown (new KeyEventArgs (k, MapKeyModifiers (k))); + OnKeyUp (new KeyEventArgs (k, MapKeyModifiers (k))); + OnKeyPressed (new KeyEventArgs (k, MapKeyModifiers (k))); } // Cause OnKeyUp and OnKeyPressed. Note that the special handling for ESC above // will not impact KeyUp. // This is causing ESC firing even if another keystroke was handled. //if (wch == Curses.KeyTab) { - // keyUpHandler (new KeyEvent (MapCursesKey (wch), keyModifiers)); + // keyUpHandler (new KeyEventArgs (MapCursesKey (wch), keyModifiers)); //} else { - // keyUpHandler (new KeyEvent ((Key)wch, keyModifiers)); + // keyUpHandler (new KeyEventArgs ((Key)wch, keyModifiers)); //} } - void HandleEscSeqResponse (ref int code, ref Key k, ref int wch2, ref KeyEvent key, ref ConsoleKeyInfo [] cki) + void HandleEscSeqResponse (ref int code, ref Key k, ref int wch2, ref KeyEventArgs key, ref ConsoleKeyInfo [] cki) { ConsoleKey ck = 0; ConsoleModifiers mod = 0; @@ -603,9 +603,9 @@ void HandleEscSeqResponse (ref int code, ref Key k, ref int wch2, ref KeyEvent k } else { k = ConsoleKeyMapping.MapConsoleKeyToKey (consoleKeyInfo.Key, out _); k = ConsoleKeyMapping.MapKeyModifiers (consoleKeyInfo, k); - key = new KeyEvent (k, MapKeyModifiers (k)); - OnKeyDown (new KeyEventEventArgs (key)); - OnKeyPressed (new KeyEventEventArgs (key)); + key = new KeyEventArgs (k, MapKeyModifiers (k)); + OnKeyDown (key); + OnKeyPressed (key); } } else { cki = EscSeqUtils.ResizeArray (consoleKeyInfo, cki); @@ -778,9 +778,9 @@ public override void SendKeys (char keyChar, ConsoleKey consoleKey, bool shift, key |= Key.CtrlMask; km.Ctrl = control; } - OnKeyDown (new KeyEventEventArgs (new KeyEvent (key, km))); - OnKeyPressed (new KeyEventEventArgs (new KeyEvent (key, km))); - OnKeyUp (new KeyEventEventArgs (new KeyEvent (key, km))); + OnKeyDown (new KeyEventArgs (key, km)); + OnKeyPressed (new KeyEventArgs (key, km)); + OnKeyUp (new KeyEventArgs (key, km)); } diff --git a/Terminal.Gui/ConsoleDrivers/FakeDriver/FakeDriver.cs b/Terminal.Gui/ConsoleDrivers/FakeDriver/FakeDriver.cs index af9df98c18..9208202367 100644 --- a/Terminal.Gui/ConsoleDrivers/FakeDriver/FakeDriver.cs +++ b/Terminal.Gui/ConsoleDrivers/FakeDriver/FakeDriver.cs @@ -366,15 +366,15 @@ void ProcessInput (ConsoleKeyInfo consoleKey) var map = MapKey (consoleKey); if (map == (Key)0xffffffff) { if ((consoleKey.Modifiers & (ConsoleModifiers.Shift | ConsoleModifiers.Alt | ConsoleModifiers.Control)) != 0) { - OnKeyDown(new KeyEventEventArgs(new KeyEvent (map, keyModifiers))); - OnKeyUp (new KeyEventEventArgs (new KeyEvent (map, keyModifiers))); + OnKeyDown(new KeyEventArgs (map, keyModifiers)); + OnKeyUp (new KeyEventArgs (map, keyModifiers)); } return; } - OnKeyDown (new KeyEventEventArgs (new KeyEvent (map, keyModifiers))); - OnKeyUp (new KeyEventEventArgs (new KeyEvent (map, keyModifiers))); - OnKeyPressed (new KeyEventEventArgs (new KeyEvent (map, keyModifiers))); + OnKeyDown (new KeyEventArgs (map, keyModifiers)); + OnKeyUp (new KeyEventArgs (map, keyModifiers)); + OnKeyPressed (new KeyEventArgs (map, keyModifiers)); } /// diff --git a/Terminal.Gui/ConsoleDrivers/NetDriver.cs b/Terminal.Gui/ConsoleDrivers/NetDriver.cs index bd313ac5fc..1136aa294b 100644 --- a/Terminal.Gui/ConsoleDrivers/NetDriver.cs +++ b/Terminal.Gui/ConsoleDrivers/NetDriver.cs @@ -1125,12 +1125,12 @@ void ProcessInput (NetEvents.InputResult inputEvent) return; } if (map == Key.Null) { - OnKeyDown (new KeyEventEventArgs (new KeyEvent (map, _keyModifiers))); - OnKeyUp (new KeyEventEventArgs (new KeyEvent (map, _keyModifiers))); + OnKeyDown (new KeyEventArgs (map, _keyModifiers)); + OnKeyUp (new KeyEventArgs (map, _keyModifiers)); } else { - OnKeyDown (new KeyEventEventArgs (new KeyEvent (map, _keyModifiers))); - OnKeyUp (new KeyEventEventArgs (new KeyEvent (map, _keyModifiers))); - OnKeyPressed (new KeyEventEventArgs (new KeyEvent (map, _keyModifiers))); + OnKeyDown (new KeyEventArgs (map, _keyModifiers)); + OnKeyUp (new KeyEventArgs (map, _keyModifiers)); + OnKeyPressed (new KeyEventArgs (map, _keyModifiers)); } break; case NetEvents.EventType.Mouse: diff --git a/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs b/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs index ac442720b8..64c383fbd2 100644 --- a/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs +++ b/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs @@ -902,7 +902,7 @@ internal void ProcessInput (WindowsConsole.InputRecord inputEvent) //System.Diagnostics.Debug.WriteLine ($"wVirtualScanCode: {ke.wVirtualScanCode}"); if (map == (Key)0xffffffff) { - KeyEvent key = new KeyEvent (); + KeyEventArgs key = new KeyEventArgs (); // Shift = VK_SHIFT = 0x10 // Ctrl = VK_CONTROL = 0x11 @@ -926,17 +926,17 @@ internal void ProcessInput (WindowsConsole.InputRecord inputEvent) WindowsConsole.ControlKeyState.LeftControlPressed | WindowsConsole.ControlKeyState.EnhancedKey: case WindowsConsole.ControlKeyState.EnhancedKey: - key = new KeyEvent (Key.CtrlMask | Key.AltMask, _keyModifiers); + key = new KeyEventArgs (Key.CtrlMask | Key.AltMask, _keyModifiers); break; case WindowsConsole.ControlKeyState.LeftAltPressed: - key = new KeyEvent (Key.AltMask, _keyModifiers); + key = new KeyEventArgs (Key.AltMask, _keyModifiers); break; case WindowsConsole.ControlKeyState.RightControlPressed: case WindowsConsole.ControlKeyState.LeftControlPressed: - key = new KeyEvent (Key.CtrlMask, _keyModifiers); + key = new KeyEventArgs (Key.CtrlMask, _keyModifiers); break; case WindowsConsole.ControlKeyState.ShiftPressed: - key = new KeyEvent (Key.ShiftMask, _keyModifiers); + key = new KeyEventArgs (Key.ShiftMask, _keyModifiers); break; case WindowsConsole.ControlKeyState.NumlockOn: break; @@ -946,28 +946,28 @@ internal void ProcessInput (WindowsConsole.InputRecord inputEvent) break; default: key = inputEvent.KeyEvent.wVirtualKeyCode switch { - 0x10 => new KeyEvent (Key.ShiftMask, _keyModifiers), - 0x11 => new KeyEvent (Key.CtrlMask, _keyModifiers), - 0x12 => new KeyEvent (Key.AltMask, _keyModifiers), - _ => new KeyEvent (Key.Unknown, _keyModifiers) + 0x10 => new KeyEventArgs (Key.ShiftMask, _keyModifiers), + 0x11 => new KeyEventArgs (Key.CtrlMask, _keyModifiers), + 0x12 => new KeyEventArgs (Key.AltMask, _keyModifiers), + _ => new KeyEventArgs (Key.Unknown, _keyModifiers) }; break; } if (inputEvent.KeyEvent.bKeyDown) { - OnKeyDown (new KeyEventEventArgs (key)); + OnKeyDown (key); } else { - OnKeyUp (new KeyEventEventArgs (key)); + OnKeyUp (key); } } else { if (inputEvent.KeyEvent.bKeyDown) { // May occurs using SendKeys _keyModifiers ??= new KeyModifiers (); // Key Down - Fire KeyDown Event and KeyPressed Event - OnKeyDown (new KeyEventEventArgs (new KeyEvent (map, _keyModifiers))); + OnKeyDown (new KeyEventArgs (map, _keyModifiers)); } else { - OnKeyUp (new KeyEventEventArgs (new KeyEvent (map, _keyModifiers))); - OnKeyPressed (new KeyEventEventArgs (new KeyEvent (map, _keyModifiers))); + OnKeyUp (new KeyEventArgs (map, _keyModifiers)); + OnKeyPressed (new KeyEventArgs (map, _keyModifiers)); } } if (!inputEvent.KeyEvent.bKeyDown && inputEvent.KeyEvent.dwControlKeyState == 0) { diff --git a/Terminal.Gui/Input/KeyEventEventArgs.cs b/Terminal.Gui/Input/KeyEventEventArgs.cs deleted file mode 100644 index c7ab9e39a2..0000000000 --- a/Terminal.Gui/Input/KeyEventEventArgs.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; - -namespace Terminal.Gui { - - /// - /// Defines the event arguments for - /// - public class KeyEventEventArgs : EventArgs { - /// - /// Constructs. - /// - /// - public KeyEventEventArgs (KeyEvent ke) => KeyEvent = ke; - /// - /// The for the event. - /// - public KeyEvent KeyEvent { get; set; } - /// - /// Indicates if the current Key event has already been processed and the driver should stop notifying any other event subscriber. - /// Its important to set this value to true specially when updating any View's layout from inside the subscriber method. - /// - public bool Handled { get; set; } = false; - } -} diff --git a/Terminal.Gui/Input/Event.cs b/Terminal.Gui/Input/Keyboard.cs similarity index 65% rename from Terminal.Gui/Input/Event.cs rename to Terminal.Gui/Input/Keyboard.cs index 995e463cf6..706d3c0458 100644 --- a/Terminal.Gui/Input/Event.cs +++ b/Terminal.Gui/Input/Keyboard.cs @@ -1,10 +1,4 @@ -// -// Evemts.cs: Events, Key mappings -// -// Authors: -// Miguel de Icaza (miguel@gnome.org) -// -using System; +using System; namespace Terminal.Gui { @@ -535,10 +529,22 @@ public enum Key : uint { } /// - /// Describes a keyboard event. + /// Defines the event arguments for keyboard input. /// - public class KeyEvent { - KeyModifiers keyModifiers; + public class KeyEventArgs : EventArgs { + /// + /// Constructs. + /// + /// + public KeyEventArgs (Key key) => Key = key; + + /// + /// Indicates if the current event has already been processed and the driver should stop notifying any other event subscriber. + /// Its important to set this value to true specially when updating any View's layout from inside the subscriber method. + /// + public bool Handled { get; set; } = false; + + KeyModifiers _keyModifiers; /// /// Symbolic definition for the key. @@ -556,269 +562,86 @@ public class KeyEvent { /// Gets a value indicating whether the Shift key was pressed. /// /// true if is shift; otherwise, false. - public bool IsShift => keyModifiers.Shift || Key == Key.BackTab; + public bool IsShift => _keyModifiers.Shift || Key == Key.BackTab; /// /// Gets a value indicating whether the Alt key was pressed (real or synthesized) /// /// true if is alternate; otherwise, false. - public bool IsAlt => keyModifiers.Alt; + public bool IsAlt => _keyModifiers.Alt; /// /// 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); - public bool IsCtrl => keyModifiers.Ctrl; + public bool IsCtrl => _keyModifiers.Ctrl; /// /// Gets a value indicating whether the Caps lock key was pressed (real or synthesized) /// /// true if is alternate; otherwise, false. - public bool IsCapslock => keyModifiers.Capslock; + public bool IsCapslock => _keyModifiers.Capslock; /// /// Gets a value indicating whether the Num lock key was pressed (real or synthesized) /// /// true if is alternate; otherwise, false. - public bool IsNumlock => keyModifiers.Numlock; + public bool IsNumlock => _keyModifiers.Numlock; /// /// Gets a value indicating whether the Scroll lock key was pressed (real or synthesized) /// /// true if is alternate; otherwise, false. - public bool IsScrolllock => keyModifiers.Scrolllock; + public bool IsScrolllock => _keyModifiers.Scrolllock; /// - /// Constructs a new + /// Constructs a new /// - public KeyEvent () + public KeyEventArgs () { Key = Key.Unknown; - keyModifiers = new KeyModifiers (); + _keyModifiers = new KeyModifiers (); } /// - /// Constructs a new from the provided Key value - can be a rune cast into a Key value + /// Constructs a new from the provided Key value - can be a rune cast into a Key value /// - public KeyEvent (Key k, KeyModifiers km) + public KeyEventArgs (Key k, KeyModifiers km) { Key = k; - keyModifiers = km; + _keyModifiers = km; } /// - /// Pretty prints the KeyEvent + /// Pretty prints the KeyEventArgs /// /// public override string ToString () { string msg = ""; - var key = this.Key; - if (keyModifiers.Shift) { + if (_keyModifiers.Shift) { msg += "Shift-"; } - if (keyModifiers.Alt) { + if (_keyModifiers.Alt) { msg += "Alt-"; } - if (keyModifiers.Ctrl) { + if (_keyModifiers.Ctrl) { msg += "Ctrl-"; } - if (keyModifiers.Capslock) { + if (_keyModifiers.Capslock) { msg += "Capslock-"; } - if (keyModifiers.Numlock) { + if (_keyModifiers.Numlock) { msg += "Numlock-"; } - if (keyModifiers.Scrolllock) { + if (_keyModifiers.Scrolllock) { msg += "Scrolllock-"; } - msg += $"{((Key)KeyValue != Key.Unknown && ((uint)this.KeyValue & (uint)Key.CharMask) > 27 ? $"{(char)this.KeyValue}" : $"{key}")}"; + msg += $"{((Key)KeyValue != Key.Unknown && ((uint)this.KeyValue & (uint)Key.CharMask) > 27 ? $"{(char)KeyValue}" : $"{Key}")}"; return msg; } } - - /// - /// Mouse flags reported in . - /// - /// - /// 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 down. - /// - WheeledDown = unchecked((int)0x20000000), - /// - /// Vertical button wheeled up while pressing ButtonShift. - /// - WheeledLeft = ButtonShift | WheeledUp, - /// - /// Vertical button wheeled down while pressing ButtonShift. - /// - WheeledRight = ButtonShift | WheeledDown, - /// - /// Mask that captures all the events. - /// - AllEvents = unchecked((int)0x7ffffff), - } - - // TODO: Merge MouseEvent and MouseEventEventArgs into a single class. - - /// - /// Low-level construct that conveys the details of mouse events, such - /// as coordinates and button state, from ConsoleDrivers up to and - /// Views. - /// - /// The class includes the - /// Action which takes a MouseEvent argument. - public class MouseEvent { - /// - /// The X (column) location for the mouse event. - /// - public int X { get; set; } - - /// - /// The Y (column) location for the mouse event. - /// - public int Y { get; set; } - - /// - /// Flags indicating the kind of mouse event that is being posted. - /// - public MouseFlags Flags { get; set; } - - /// - /// The offset X (column) location for the mouse event. - /// - public int OfX { get; set; } - - /// - /// The offset Y (column) location for the mouse event. - /// - public int OfY { get; set; } - - /// - /// The current view at the location for the mouse event. - /// - public View View { get; set; } - - /// - /// Indicates if the current mouse event has already been processed and the driver should stop notifying any other event subscriber. - /// Its important to set this value to true specially when updating any View's layout from inside the subscriber method. - /// - public bool Handled { get; set; } - - /// - /// Returns a that represents the current . - /// - /// A that represents the current . - public override string ToString () - { - return $"({X},{Y}:{Flags}"; - } - } } diff --git a/Terminal.Gui/Input/Mouse.cs b/Terminal.Gui/Input/Mouse.cs new file mode 100644 index 0000000000..15b7951195 --- /dev/null +++ b/Terminal.Gui/Input/Mouse.cs @@ -0,0 +1,186 @@ +using System; + +namespace Terminal.Gui { + + /// + /// Mouse flags reported in . + /// + /// + /// 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 down. + /// + WheeledDown = unchecked((int)0x20000000), + /// + /// Vertical button wheeled up while pressing ButtonShift. + /// + WheeledLeft = ButtonShift | WheeledUp, + /// + /// Vertical button wheeled down while pressing ButtonShift. + /// + WheeledRight = ButtonShift | WheeledDown, + /// + /// Mask that captures all the events. + /// + AllEvents = unchecked((int)0x7ffffff), + } + + // TODO: Merge MouseEvent and MouseEventEventArgs into a single class. + + /// + /// Low-level construct that conveys the details of mouse events, such + /// as coordinates and button state, from ConsoleDrivers up to and + /// Views. + /// + /// The class includes the + /// Action which takes a MouseEvent argument. + public class MouseEvent { + /// + /// The X (column) location for the mouse event. + /// + public int X { get; set; } + + /// + /// The Y (column) location for the mouse event. + /// + public int Y { get; set; } + + /// + /// Flags indicating the kind of mouse event that is being posted. + /// + public MouseFlags Flags { get; set; } + + /// + /// The offset X (column) location for the mouse event. + /// + public int OfX { get; set; } + + /// + /// The offset Y (column) location for the mouse event. + /// + public int OfY { get; set; } + + /// + /// The current view at the location for the mouse event. + /// + public View View { get; set; } + + /// + /// Indicates if the current mouse event has already been processed and the driver should stop notifying any other event subscriber. + /// Its important to set this value to true specially when updating any View's layout from inside the subscriber method. + /// + public bool Handled { get; set; } + + /// + /// Returns a that represents the current . + /// + /// A that represents the current . + public override string ToString () + { + return $"({X},{Y}:{Flags}"; + } + } +} diff --git a/Terminal.Gui/Input/Responder.cs b/Terminal.Gui/Input/Responder.cs index c043a40948..1ec2f7176d 100644 --- a/Terminal.Gui/Input/Responder.cs +++ b/Terminal.Gui/Input/Responder.cs @@ -20,7 +20,7 @@ namespace Terminal.Gui { /// - /// Responder base class implemented by objects that want to participate on keyboard and mouse input. + /// Base class for classes that want to participate on keyboard and mouse input (e.g. ). /// public class Responder : IDisposable { bool disposedValue; @@ -71,20 +71,24 @@ public Responder () // Key handling /// - /// This method can be overwritten by view that + /// This method can be overwritten views that /// want to provide accelerator functionality /// (Alt-key for example). /// /// + /// + /// This is a low-level API; see for the preferred way to define what keys + /// a View should respond to. + /// /// - /// Before keys are sent to the subview on the - /// current view, all the views are - /// processed and the key is passed to the widgets - /// to allow some of them to process the keystroke + /// Before keys are sent to a subview of the + /// current view, all subviews are + /// processed and the key is passed to them + /// to allow them to process the keystroke /// as a hot-key. /// - /// For example, if you implement a button that - /// has a hotkey ok "o", you would catch the + /// For example, for a button that + /// has a hotkey Alt-o, catch the /// combination Alt-o here. If the event is /// caught, you must return true to stop the /// keystroke from being dispatched to other @@ -92,39 +96,32 @@ public Responder () /// /// - public virtual bool ProcessHotKey (KeyEvent kb) + public virtual bool ProcessHotKey (KeyEventArgs kb) { return false; } /// - /// If the view is focused, gives the view a - /// chance to process the keystroke. + /// Called after a key has been pressed and released. Fires the event. + /// + /// Called for new KeyPressed events before any processing is performed or + /// views evaluate. Use for global key handling and/or debugging. + /// /// - /// - /// - /// Views can override this method if they are - /// interested in processing the given keystroke. - /// If they consume the keystroke, they must - /// return true to stop the keystroke from being - /// processed by other widgets or consumed by the - /// widget engine. If they return false, the - /// keystroke will be passed using the ProcessColdKey - /// method to other views to process. - /// - /// - /// The View implementation does nothing but return false, - /// so it is not necessary to call base.ProcessKey if you - /// derive directly from View, but you should if you derive - /// other View subclasses. - /// - /// - /// Contains the details about the key that produced the event. - public virtual bool ProcessKey (KeyEvent keyEvent) + /// + /// if the key was handled. + public virtual bool OnKeyPressed (KeyEventArgs arg) { - return false; + KeyPressed?.Invoke (this, arg); + return arg.Handled; } + /// + /// Event fired after a key has been pressed and released. + /// Set to to suppress the event. + /// + public event EventHandler KeyPressed; + /// /// This method can be overwritten by views that /// want to provide accelerator functionality @@ -132,6 +129,10 @@ public virtual bool ProcessKey (KeyEvent keyEvent) /// interefering with normal ProcessKey behavior. /// /// + /// + /// This is a low-level API; see for the preferred way to define what keys + /// a View should respond to. + /// /// /// After keys are sent to the subviews on the /// current view, all the view are @@ -147,7 +148,7 @@ public virtual bool ProcessKey (KeyEvent keyEvent) /// /// /// Contains the details about the key that produced the event. - public virtual bool ProcessColdKey (KeyEvent keyEvent) + public virtual bool ProcessColdKey (KeyEventArgs keyEvent) { return false; } @@ -157,7 +158,7 @@ public virtual bool ProcessColdKey (KeyEvent keyEvent) /// /// Contains the details about the key that produced the event. /// true if the event was handled - public virtual bool OnKeyDown (KeyEvent keyEvent) + public virtual bool OnKeyDown (KeyEventArgs keyEvent) { return false; } @@ -167,7 +168,7 @@ public virtual bool OnKeyDown (KeyEvent keyEvent) /// /// Contains the details about the key that produced the event. /// true if the event was handled - public virtual bool OnKeyUp (KeyEvent keyEvent) + public virtual bool OnKeyUp (KeyEventArgs keyEvent) { return false; } @@ -256,7 +257,7 @@ internal static bool IsOverridden (Responder subclass, string method) } return m.GetBaseDefinition ().DeclaringType != m.DeclaringType; } - + /// /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. /// @@ -278,11 +279,11 @@ protected virtual void Dispose (bool disposing) #if DEBUG_IDISPOSABLE Instances.Remove (this); -#endif +#endif disposedValue = true; } } - + /// /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resource. /// diff --git a/Terminal.Gui/Input/ShortcutHelper.cs b/Terminal.Gui/Input/ShortcutHelper.cs index e1b1a3bdbb..02efc2fb60 100644 --- a/Terminal.Gui/Input/ShortcutHelper.cs +++ b/Terminal.Gui/Input/ShortcutHelper.cs @@ -38,7 +38,7 @@ public virtual Key Shortcut { /// /// The to check. /// The with all the keys modifiers. - public static Key GetModifiersKey (KeyEvent kb) + public static Key GetModifiersKey (KeyEventArgs kb) { var key = kb.Key; if (kb.IsAlt && (key & Key.AltMask) == 0) { @@ -240,7 +240,7 @@ public static bool PostShortcutValidation (Key key) /// The /// The /// true if defined falseotherwise. - public static bool FindAndOpenByShortcut (KeyEvent kb, View view = null) + public static bool FindAndOpenByShortcut (KeyEventArgs kb, View view = null) { if (view == null) { return false; } diff --git a/Terminal.Gui/Text/Autocomplete/AppendAutocomplete.cs b/Terminal.Gui/Text/Autocomplete/AppendAutocomplete.cs index 9aba845ede..a1c91c387a 100644 --- a/Terminal.Gui/Text/Autocomplete/AppendAutocomplete.cs +++ b/Terminal.Gui/Text/Autocomplete/AppendAutocomplete.cs @@ -54,7 +54,7 @@ public override bool MouseEvent (MouseEvent me, bool fromHost = false) } /// - public override bool ProcessKey (KeyEvent kb) + public override bool ProcessKey (KeyEventArgs kb) { var key = kb.Key; if (key == SelectionKey) { diff --git a/Terminal.Gui/Text/Autocomplete/AutocompleteBase.cs b/Terminal.Gui/Text/Autocomplete/AutocompleteBase.cs index 6be3e8da00..4f2db0036e 100644 --- a/Terminal.Gui/Text/Autocomplete/AutocompleteBase.cs +++ b/Terminal.Gui/Text/Autocomplete/AutocompleteBase.cs @@ -55,7 +55,7 @@ public abstract class AutocompleteBase : IAutocomplete { public abstract bool MouseEvent (MouseEvent me, bool fromHost = false); /// - public abstract bool ProcessKey (KeyEvent kb); + public abstract bool ProcessKey (KeyEventArgs kb); /// public abstract void RenderOverlay (Point renderAt); diff --git a/Terminal.Gui/Text/Autocomplete/IAutocomplete.cs b/Terminal.Gui/Text/Autocomplete/IAutocomplete.cs index ac31d3f9c7..d60ca09da4 100644 --- a/Terminal.Gui/Text/Autocomplete/IAutocomplete.cs +++ b/Terminal.Gui/Text/Autocomplete/IAutocomplete.cs @@ -87,7 +87,7 @@ public interface IAutocomplete { /// /// The key event. /// trueif the key can be handled falseotherwise. - bool ProcessKey (KeyEvent kb); + bool ProcessKey (KeyEventArgs kb); /// /// Handle mouse events before e.g. to make mouse events like diff --git a/Terminal.Gui/Text/Autocomplete/PopupAutocomplete.cs b/Terminal.Gui/Text/Autocomplete/PopupAutocomplete.cs index 925f5bc53b..c4b7bcdbbf 100644 --- a/Terminal.Gui/Text/Autocomplete/PopupAutocomplete.cs +++ b/Terminal.Gui/Text/Autocomplete/PopupAutocomplete.cs @@ -152,7 +152,7 @@ public override ColorScheme ColorScheme { public override void RenderOverlay (Point renderAt) { if (!Context.Canceled && Suggestions.Count > 0 && !Visible && HostControl?.HasFocus == true) { - ProcessKey (new KeyEvent ((Key)(Suggestions [0].Title [0]), new KeyModifiers ())); + ProcessKey (new KeyEventArgs ((Key)(Suggestions [0].Title [0]), new KeyModifiers ())); } else if (!Visible || HostControl?.HasFocus == false || Suggestions.Count == 0) { LastPopupPos = null; Visible = false; @@ -278,7 +278,7 @@ public override void EnsureSelectedIdxIsValid () /// /// The key event. /// trueif the key can be handled falseotherwise. - public override bool ProcessKey (KeyEvent kb) + public override bool ProcessKey (KeyEventArgs kb) { if (SuggestionGenerator.IsWordChar ((Rune)(char)kb.Key)) { Visible = true; diff --git a/Terminal.Gui/Text/CollectionNavigatorBase.cs b/Terminal.Gui/Text/CollectionNavigatorBase.cs index 1d65116dc6..75b012f57b 100644 --- a/Terminal.Gui/Text/CollectionNavigatorBase.cs +++ b/Terminal.Gui/Text/CollectionNavigatorBase.cs @@ -209,7 +209,7 @@ private void ClearSearchString () /// /// /// - public static bool IsCompatibleKey (KeyEvent kb) + public static bool IsCompatibleKey (KeyEventArgs kb) { return !kb.IsAlt && !kb.IsCtrl; } diff --git a/Terminal.Gui/View/ViewKeyboard.cs b/Terminal.Gui/View/ViewKeyboard.cs index 421f941621..d69cb13861 100644 --- a/Terminal.Gui/View/ViewKeyboard.cs +++ b/Terminal.Gui/View/ViewKeyboard.cs @@ -163,43 +163,44 @@ public bool TabStop { /// /// Invoked when a character key is pressed and occurs after the key up event. /// - public event EventHandler KeyPressed; + public event EventHandler KeyPressed; /// - public override bool ProcessKey (KeyEvent keyEvent) + public override bool OnKeyPressed (KeyEventArgs arg) { if (!Enabled) { return false; } - var args = new KeyEventEventArgs (keyEvent); - KeyPressed?.Invoke (this, args); - if (args.Handled) + KeyPressed?.Invoke (this, arg); + if (arg.Handled) { return true; + } if (Focused?.Enabled == true) { - Focused?.KeyPressed?.Invoke (this, args); - if (args.Handled) + Focused?.KeyPressed?.Invoke (this, arg); + if (arg.Handled) { return true; + } } - return Focused?.Enabled == true && Focused?.ProcessKey (keyEvent) == true; + return Focused?.Enabled == true && Focused?.OnKeyPressed (arg) == true; } /// /// Invokes any binding that is registered on this - /// and matches the + /// and matches the /// - /// The key event passed. - protected bool? InvokeKeybindings (KeyEvent keyEvent) + /// The key event passed. + protected bool? InvokeKeybindings (KeyEventArgs KeyEventArgs) { bool? toReturn = null; - if (KeyBindings.ContainsKey (keyEvent.Key)) { + if (KeyBindings.ContainsKey (KeyEventArgs.Key)) { - foreach (var command in KeyBindings [keyEvent.Key]) { + foreach (var command in KeyBindings [KeyEventArgs.Key]) { if (!CommandImplementations.ContainsKey (command)) { - throw new NotSupportedException ($"A KeyBinding was set up for the command {command} ({keyEvent.Key}) but that command is not supported by this View ({GetType ().Name})"); + throw new NotSupportedException ($"A KeyBinding was set up for the command {command} ({KeyEventArgs.Key}) but that command is not supported by this View ({GetType ().Name})"); } // each command has its own return value @@ -340,52 +341,54 @@ public Key GetKeyFromCommand (params Command [] command) } /// - public override bool ProcessHotKey (KeyEvent keyEvent) + public override bool ProcessHotKey (KeyEventArgs arg) { if (!Enabled) { return false; } - var args = new KeyEventEventArgs (keyEvent); if (MostFocused?.Enabled == true) { - MostFocused?.KeyPressed?.Invoke (this, args); - if (args.Handled) + MostFocused?.KeyPressed?.Invoke (this, arg); + if (arg.Handled) { return true; + } } - if (MostFocused?.Enabled == true && MostFocused?.ProcessKey (keyEvent) == true) + if (MostFocused?.Enabled == true && MostFocused?.OnKeyPressed (arg) == true) { return true; - if (_subviews == null || _subviews.Count == 0) + } + if (_subviews == null || _subviews.Count == 0) { return false; + } foreach (var view in _subviews) - if (view.Enabled && view.ProcessHotKey (keyEvent)) + if (view.Enabled && view.ProcessHotKey (arg)) { return true; + } return false; } /// - public override bool ProcessColdKey (KeyEvent keyEvent) + public override bool ProcessColdKey (KeyEventArgs arg) { if (!Enabled) { return false; } - var args = new KeyEventEventArgs (keyEvent); - KeyPressed?.Invoke (this, args); - if (args.Handled) + KeyPressed?.Invoke (this, arg); + if (arg.Handled) return true; if (MostFocused?.Enabled == true) { - MostFocused?.KeyPressed?.Invoke (this, args); - if (args.Handled) + MostFocused?.KeyPressed?.Invoke (this, arg); + if (arg.Handled) return true; } - if (MostFocused?.Enabled == true && MostFocused?.ProcessKey (keyEvent) == true) + if (MostFocused?.Enabled == true && MostFocused?.OnKeyPressed (arg) == true) return true; if (_subviews == null || _subviews.Count == 0) return false; foreach (var view in _subviews) - if (view.Enabled && view.ProcessColdKey (keyEvent)) + if (view.Enabled && view.ProcessColdKey (arg)) return true; return false; } @@ -393,26 +396,25 @@ public override bool ProcessColdKey (KeyEvent keyEvent) /// /// Invoked when a key is pressed. /// - public event EventHandler KeyDown; + public event EventHandler KeyDown; /// - public override bool OnKeyDown (KeyEvent keyEvent) + public override bool OnKeyDown (KeyEventArgs arg) { if (!Enabled) { return false; } - var args = new KeyEventEventArgs (keyEvent); - KeyDown?.Invoke (this, args); - if (args.Handled) { + KeyDown?.Invoke (this, arg); + if (arg.Handled) { return true; } if (Focused?.Enabled == true) { - Focused.KeyDown?.Invoke (this, args); - if (args.Handled) { + Focused.KeyDown?.Invoke (this, arg); + if (arg.Handled) { return true; } - if (Focused?.OnKeyDown (keyEvent) == true) { + if (Focused?.OnKeyDown (arg) == true) { return true; } } @@ -423,26 +425,25 @@ public override bool OnKeyDown (KeyEvent keyEvent) /// /// Invoked when a key is released. /// - public event EventHandler KeyUp; + public event EventHandler KeyUp; /// - public override bool OnKeyUp (KeyEvent keyEvent) + public override bool OnKeyUp (KeyEventArgs arg) { if (!Enabled) { return false; } - var args = new KeyEventEventArgs (keyEvent); - KeyUp?.Invoke (this, args); - if (args.Handled) { + KeyUp?.Invoke (this, arg); + if (arg.Handled) { return true; } if (Focused?.Enabled == true) { - Focused.KeyUp?.Invoke (this, args); - if (args.Handled) { + Focused.KeyUp?.Invoke (this, arg); + if (arg.Handled) { return true; } - if (Focused?.OnKeyUp (keyEvent) == true) { + if (Focused?.OnKeyUp (arg) == true) { return true; } } diff --git a/Terminal.Gui/Views/Button.cs b/Terminal.Gui/Views/Button.cs index 5cd1605dd9..6d647455d7 100644 --- a/Terminal.Gui/Views/Button.cs +++ b/Terminal.Gui/Views/Button.cs @@ -191,7 +191,7 @@ protected override void UpdateTextFormatterText () } /// - public override bool ProcessHotKey (KeyEvent kb) + public override bool ProcessHotKey (KeyEventArgs kb) { if (!Enabled) { return false; @@ -201,7 +201,7 @@ public override bool ProcessHotKey (KeyEvent kb) } /// - public override bool ProcessColdKey (KeyEvent kb) + public override bool ProcessColdKey (KeyEventArgs kb) { if (!Enabled) { return false; @@ -211,20 +211,20 @@ public override bool ProcessColdKey (KeyEvent kb) } /// - public override bool ProcessKey (KeyEvent kb) + public override bool OnKeyPressed (KeyEventArgs arg) { if (!Enabled) { return false; } - var result = InvokeKeybindings (kb); + var result = InvokeKeybindings (arg); if (result != null) return (bool)result; - return base.ProcessKey (kb); + return base.OnKeyPressed (arg); } - bool ExecuteHotKey (KeyEvent ke) + bool ExecuteHotKey (KeyEventArgs ke) { if (ke.Key == (Key.AltMask | HotKey)) { return AcceptKey (); @@ -232,7 +232,7 @@ bool ExecuteHotKey (KeyEvent ke) return false; } - bool ExecuteColdKey (KeyEvent ke) + bool ExecuteColdKey (KeyEventArgs ke) { if (IsDefault && ke.KeyValue == '\n') { return AcceptKey (); diff --git a/Terminal.Gui/Views/CheckBox.cs b/Terminal.Gui/Views/CheckBox.cs index e8eaf8088f..4a21a8c016 100644 --- a/Terminal.Gui/Views/CheckBox.cs +++ b/Terminal.Gui/Views/CheckBox.cs @@ -168,17 +168,17 @@ public override void PositionCursor () } /// - public override bool ProcessKey (KeyEvent kb) + public override bool OnKeyPressed (KeyEventArgs arg) { - var result = InvokeKeybindings (kb); + var result = InvokeKeybindings (arg); if (result != null) return (bool)result; - return base.ProcessKey (kb); + return base.OnKeyPressed (arg); } /// - public override bool ProcessHotKey (KeyEvent kb) + public override bool ProcessHotKey (KeyEventArgs kb) { if (kb.Key == (Key.AltMask | HotKey)) return ToggleChecked (); diff --git a/Terminal.Gui/Views/ColorPicker.cs b/Terminal.Gui/Views/ColorPicker.cs index f41aa5b68d..7bf28a2a00 100644 --- a/Terminal.Gui/Views/ColorPicker.cs +++ b/Terminal.Gui/Views/ColorPicker.cs @@ -251,9 +251,9 @@ public virtual bool MoveDown () } /// - public override bool ProcessKey (KeyEvent kb) + public override bool OnKeyPressed (KeyEventArgs arg) { - var result = InvokeKeybindings (kb); + var result = InvokeKeybindings (arg); if (result != null) return (bool)result; diff --git a/Terminal.Gui/Views/ComboBox.cs b/Terminal.Gui/Views/ComboBox.cs index 211a11d529..d1f79075e3 100644 --- a/Terminal.Gui/Views/ComboBox.cs +++ b/Terminal.Gui/Views/ComboBox.cs @@ -545,13 +545,13 @@ public override void OnDrawContent (Rect contentArea) } /// - public override bool ProcessKey (KeyEvent e) + public override bool OnKeyPressed (KeyEventArgs arg) { - var result = InvokeKeybindings (e); + var result = InvokeKeybindings (arg); if (result != null) return (bool)result; - return base.ProcessKey (e); + return base.OnKeyPressed (arg); } bool UnixEmulation () diff --git a/Terminal.Gui/Views/DateField.cs b/Terminal.Gui/Views/DateField.cs index 2da853331f..2b063e1c13 100644 --- a/Terminal.Gui/Views/DateField.cs +++ b/Terminal.Gui/Views/DateField.cs @@ -328,14 +328,14 @@ void AdjCursorPosition () } /// - public override bool ProcessKey (KeyEvent kb) + public override bool OnKeyPressed (KeyEventArgs arg) { - var result = InvokeKeybindings (kb); + var result = InvokeKeybindings (arg); if (result != null) { return (bool)result; } // Ignore non-numeric characters. - if (kb.Key < (Key)((int)'0') || kb.Key > (Key)((int)'9')) { + if (arg.Key < (Key)((int)'0') || arg.Key > (Key)((int)'9')) { return false; } @@ -344,7 +344,7 @@ public override bool ProcessKey (KeyEvent kb) } // BUGBUG: This is a hack, we should be able to just use ((Rune)(uint)kb.Key) directly. - if (SetText (((Rune)(uint)kb.Key).ToString ().EnumerateRunes ().First ())) { + if (SetText (((Rune)(uint)arg.Key).ToString ().EnumerateRunes ().First ())) { IncCursorPosition (); } diff --git a/Terminal.Gui/Views/Dialog.cs b/Terminal.Gui/Views/Dialog.cs index db7016394b..67326aa282 100644 --- a/Terminal.Gui/Views/Dialog.cs +++ b/Terminal.Gui/Views/Dialog.cs @@ -229,14 +229,14 @@ void LayoutButtons () } /// - public override bool ProcessKey (KeyEvent kb) + public override bool OnKeyPressed (KeyEventArgs arg) { - switch (kb.Key) { + switch (arg.Key) { case Key.Esc: Application.RequestStop (this); return true; } - return base.ProcessKey (kb); + return base.OnKeyPressed (arg); } } } diff --git a/Terminal.Gui/Views/FileDialog.cs b/Terminal.Gui/Views/FileDialog.cs index 725bbfa86d..5138a06849 100644 --- a/Terminal.Gui/Views/FileDialog.cs +++ b/Terminal.Gui/Views/FileDialog.cs @@ -286,12 +286,12 @@ public FileDialog (IFileSystem fileSystem) tbFind.TextChanged += (s, o) => RestartSearch (); tbFind.KeyPressed += (s, o) => { - if (o.KeyEvent.Key == Key.Enter) { + if (o.Key == Key.Enter) { RestartSearch (); o.Handled = true; } - if (o.KeyEvent.Key == Key.Esc) { + if (o.Key == Key.Esc) { if (CancelSearch ()) { o.Handled = true; } @@ -316,7 +316,7 @@ public FileDialog (IFileSystem fileSystem) this.tbPath.TextChanged += (s, e) => this.PathChanged (); this.tableView.CellActivated += this.CellActivate; - this.tableView.KeyUp += (s, k) => k.Handled = this.TableView_KeyUp (k.KeyEvent); + this.tableView.KeyUp += (s, k) => k.Handled = this.TableView_KeyUp (k); this.tableView.SelectedCellChanged += this.TableView_SelectedCellChanged; this.tableView.AddKeyBinding (Key.Home, Command.TopHome); @@ -340,7 +340,7 @@ public FileDialog (IFileSystem fileSystem) return; } - k.Handled = this.TreeView_KeyDown (k.KeyEvent); + k.Handled = this.TreeView_KeyDown (k); }; @@ -485,7 +485,7 @@ private IFileSystemInfo [] GetFocusedFiles () /// - public override bool ProcessHotKey (KeyEvent keyEvent) + public override bool ProcessHotKey (KeyEventArgs keyEvent) { if (this.NavigateIf (keyEvent, Key.CtrlMask | Key.F, this.tbFind)) { return true; @@ -772,17 +772,17 @@ private void AllowedTypeMenuClicked (int idx) } } - private void SuppressIfBadChar (KeyEventEventArgs k) + private void SuppressIfBadChar (KeyEventArgs k) { // don't let user type bad letters - var ch = (char)k.KeyEvent.KeyValue; + var ch = (char)k.KeyValue; if (badChars.Contains (ch)) { k.Handled = true; } } - private bool TreeView_KeyDown (KeyEvent keyEvent) + private bool TreeView_KeyDown (KeyEventArgs keyEvent) { if (this.treeView.HasFocus && Separators.Contains ((char)keyEvent.KeyValue)) { this.tbPath.FocusFirst (); @@ -794,9 +794,9 @@ private bool TreeView_KeyDown (KeyEvent keyEvent) return false; } - private void AcceptIf (KeyEventEventArgs keyEvent, Key isKey) + private void AcceptIf (KeyEventArgs keyEvent, Key isKey) { - if (!keyEvent.Handled && keyEvent.KeyEvent.Key == isKey) { + if (!keyEvent.Handled && keyEvent.Key == isKey) { keyEvent.Handled = true; // User hit Enter in text box so probably wants the @@ -880,17 +880,7 @@ private void FinishAccept () Application.RequestStop (); } - private void NavigateIf (KeyEventEventArgs keyEvent, Key isKey, View to) - { - if (!keyEvent.Handled) { - - if (NavigateIf (keyEvent.KeyEvent, isKey, to)) { - keyEvent.Handled = true; - } - } - } - - private bool NavigateIf (KeyEvent keyEvent, Key isKey, View to) + private bool NavigateIf (KeyEventArgs keyEvent, Key isKey, View to) { if (keyEvent.Key == isKey) { @@ -956,7 +946,7 @@ private void TableView_SelectedCellChanged (object sender, SelectedCellChangedEv } } - private bool TableView_KeyUp (KeyEvent keyEvent) + private bool TableView_KeyUp (KeyEventArgs keyEvent) { if (keyEvent.Key == Key.Backspace) { return this.history.Back (); diff --git a/Terminal.Gui/Views/GraphView/GraphView.cs b/Terminal.Gui/Views/GraphView/GraphView.cs index 2d2310b1b2..bdf6d9f00d 100644 --- a/Terminal.Gui/Views/GraphView/GraphView.cs +++ b/Terminal.Gui/Views/GraphView/GraphView.cs @@ -244,7 +244,7 @@ public override bool OnEnter (View view) } /// - public override bool ProcessKey (KeyEvent keyEvent) + public override bool OnKeyPressed (KeyEventArgs keyEvent) { if (HasFocus && CanFocus) { var result = InvokeKeybindings (keyEvent); @@ -252,7 +252,7 @@ public override bool ProcessKey (KeyEvent keyEvent) return (bool)result; } - return base.ProcessKey (keyEvent); + return base.OnKeyPressed (keyEvent); } /// diff --git a/Terminal.Gui/Views/HexView.cs b/Terminal.Gui/Views/HexView.cs index b425e5f073..e5d520f331 100644 --- a/Terminal.Gui/Views/HexView.cs +++ b/Terminal.Gui/Views/HexView.cs @@ -424,7 +424,7 @@ bool MoveDown (int bytes) } /// - public override bool ProcessKey (KeyEvent keyEvent) + public override bool OnKeyPressed (KeyEventArgs keyEvent) { var result = InvokeKeybindings (keyEvent); if (result != null) diff --git a/Terminal.Gui/Views/Label.cs b/Terminal.Gui/Views/Label.cs index 29b476fb77..bd8aa813ba 100644 --- a/Terminal.Gui/Views/Label.cs +++ b/Terminal.Gui/Views/Label.cs @@ -112,7 +112,7 @@ public override bool OnEnter (View view) } /// - public override bool ProcessHotKey (KeyEvent ke) + public override bool ProcessHotKey (KeyEventArgs ke) { if (ke.Key == (Key.AltMask | HotKey)) { if (!HasFocus) { diff --git a/Terminal.Gui/Views/ListView.cs b/Terminal.Gui/Views/ListView.cs index 59f0e9a718..6967783bef 100644 --- a/Terminal.Gui/Views/ListView.cs +++ b/Terminal.Gui/Views/ListView.cs @@ -416,10 +416,10 @@ public override void OnDrawContent (Rect contentArea) public CollectionNavigator KeystrokeNavigator { get; private set; } = new CollectionNavigator (); /// - public override bool ProcessKey (KeyEvent kb) + public override bool OnKeyPressed (KeyEventArgs kb) { if (source == null) { - return base.ProcessKey (kb); + return base.OnKeyPressed (kb); } var result = InvokeKeybindings (kb); diff --git a/Terminal.Gui/Views/Menu.cs b/Terminal.Gui/Views/Menu.cs index 7c16edc534..46f906892a 100644 --- a/Terminal.Gui/Views/Menu.cs +++ b/Terminal.Gui/Views/Menu.cs @@ -721,7 +721,7 @@ public override bool OnLeave (View view) return host.OnLeave (view); } - public override bool OnKeyDown (KeyEvent keyEvent) + public override bool OnKeyDown (KeyEventArgs keyEvent) { if (keyEvent.IsAlt) { host.CloseAllMenus (); @@ -731,7 +731,7 @@ public override bool OnKeyDown (KeyEvent keyEvent) return false; } - public override bool ProcessHotKey (KeyEvent keyEvent) + public override bool ProcessHotKey (KeyEventArgs keyEvent) { // To ncurses simulate a AltMask key pressing Alt+Space because // it can't detect an alone special key down was pressed. @@ -743,7 +743,7 @@ public override bool ProcessHotKey (KeyEvent keyEvent) return false; } - public override bool ProcessKey (KeyEvent kb) + public override bool OnKeyPressed (KeyEventArgs kb) { var result = InvokeKeybindings (kb); if (result != null) @@ -1165,7 +1165,7 @@ public override bool OnLeave (View view) } /// - public override bool OnKeyDown (KeyEvent keyEvent) + public override bool OnKeyDown (KeyEventArgs keyEvent) { if (keyEvent.IsAlt || (keyEvent.IsCtrl && keyEvent.Key == (Key.CtrlMask | Key.Space))) { openedByAltKey = true; @@ -1176,7 +1176,7 @@ public override bool OnKeyDown (KeyEvent keyEvent) } /// - public override bool OnKeyUp (KeyEvent keyEvent) + public override bool OnKeyUp (KeyEventArgs keyEvent) { if (keyEvent.IsAlt || keyEvent.Key == Key.AltMask || (keyEvent.IsCtrl && keyEvent.Key == (Key.CtrlMask | Key.Space))) { // User pressed Alt - this may be a precursor to a menu accelerator (e.g. Alt-F) @@ -1812,7 +1812,7 @@ internal void NextMenu (bool isSubMenu = false, bool ignoreUseSubMenusSingleFram } bool openedByHotKey; - internal bool FindAndOpenMenuByHotkey (KeyEvent kb) + internal bool FindAndOpenMenuByHotkey (KeyEventArgs kb) { //int pos = 0; var c = ((uint)kb.Key & (uint)Key.CharMask); @@ -1839,7 +1839,7 @@ internal bool FindAndOpenMenuByHotkey (KeyEvent kb) return false; } - bool FindAndOpenChildrenMenuByHotkey (KeyEvent kb, MenuItem [] children) + bool FindAndOpenChildrenMenuByHotkey (KeyEventArgs kb, MenuItem [] children) { var c = ((uint)kb.Key & (uint)Key.CharMask); for (int i = 0; i < children.Length; i++) { @@ -1873,7 +1873,7 @@ bool FindAndOpenChildrenMenuByHotkey (KeyEvent kb, MenuItem [] children) return false; } - internal bool FindAndOpenMenuByShortcut (KeyEvent kb, MenuItem [] children = null) + internal bool FindAndOpenMenuByShortcut (KeyEventArgs kb, MenuItem [] children = null) { if (children == null) { children = Menus; @@ -1931,7 +1931,7 @@ private void ProcessMenu (int i, MenuBarItem mi) } /// - public override bool ProcessHotKey (KeyEvent kb) + public override bool ProcessHotKey (KeyEventArgs kb) { if (kb.Key == Key) { if (Visible && !IsMenuOpen) { @@ -1957,7 +1957,7 @@ public override bool ProcessHotKey (KeyEvent kb) } /// - public override bool ProcessKey (KeyEvent kb) + public override bool OnKeyPressed (KeyEventArgs kb) { if (InvokeKeybindings (kb) == true) return true; @@ -2013,7 +2013,7 @@ void MoveLeft () } /// - public override bool ProcessColdKey (KeyEvent kb) + public override bool ProcessColdKey (KeyEventArgs kb) { return FindAndOpenMenuByShortcut (kb); } diff --git a/Terminal.Gui/Views/RadioGroup.cs b/Terminal.Gui/Views/RadioGroup.cs index db4656f4f3..2920a1d1c7 100644 --- a/Terminal.Gui/Views/RadioGroup.cs +++ b/Terminal.Gui/Views/RadioGroup.cs @@ -288,7 +288,7 @@ public virtual void OnSelectedItemChanged (int selectedItem, int previousSelecte } /// - public override bool ProcessColdKey (KeyEvent kb) + public override bool ProcessColdKey (KeyEventArgs kb) { var key = kb.KeyValue; if (key < Char.MaxValue && Char.IsLetterOrDigit ((char)key)) { @@ -318,13 +318,13 @@ public override bool ProcessColdKey (KeyEvent kb) } /// - public override bool ProcessKey (KeyEvent kb) + public override bool OnKeyPressed (KeyEventArgs kb) { var result = InvokeKeybindings (kb); if (result != null) return (bool)result; - return base.ProcessKey (kb); + return base.OnKeyPressed (kb); } void SelectItem () diff --git a/Terminal.Gui/Views/ScrollView.cs b/Terminal.Gui/Views/ScrollView.cs index bb83466360..b9aeb9a4b1 100644 --- a/Terminal.Gui/Views/ScrollView.cs +++ b/Terminal.Gui/Views/ScrollView.cs @@ -542,12 +542,12 @@ public bool ScrollRight (int cols) } /// - public override bool ProcessKey (KeyEvent kb) + public override bool OnKeyPressed (KeyEventArgs arg) { - if (base.ProcessKey (kb)) + if (base.OnKeyPressed (arg)) return true; - var result = InvokeKeybindings (kb); + var result = InvokeKeybindings (arg); if (result != null) return (bool)result; diff --git a/Terminal.Gui/Views/Slider.cs b/Terminal.Gui/Views/Slider.cs index a490516c5f..f5c311ebe7 100644 --- a/Terminal.Gui/Views/Slider.cs +++ b/Terminal.Gui/Views/Slider.cs @@ -1432,17 +1432,17 @@ void SetKeyBindings () } /// - public override bool ProcessKey (KeyEvent keyEvent) + public override bool OnKeyPressed (KeyEventArgs keyEvent) { if (!CanFocus || !HasFocus) { - return base.ProcessKey (keyEvent); + return base.OnKeyPressed (keyEvent); } var result = InvokeKeybindings (keyEvent); if (result != null) { return (bool)result; } - return base.ProcessKey (keyEvent); + return base.OnKeyPressed (keyEvent); } Dictionary> GetSetOptionDictionary () => _setOptions.ToDictionary (e => e, e => _options [e]); diff --git a/Terminal.Gui/Views/StatusBar.cs b/Terminal.Gui/Views/StatusBar.cs index 1d66b853dd..f6bb3fdbda 100644 --- a/Terminal.Gui/Views/StatusBar.cs +++ b/Terminal.Gui/Views/StatusBar.cs @@ -177,7 +177,7 @@ public override void OnDrawContent (Rect contentArea) } /// - public override bool ProcessHotKey (KeyEvent kb) + public override bool ProcessHotKey (KeyEventArgs kb) { foreach (var item in Items) { if (kb.Key == item.Shortcut) { diff --git a/Terminal.Gui/Views/TabView.cs b/Terminal.Gui/Views/TabView.cs index 86a558b82d..da11b6b6af 100644 --- a/Terminal.Gui/Views/TabView.cs +++ b/Terminal.Gui/Views/TabView.cs @@ -230,15 +230,15 @@ protected virtual void OnSelectedTabChanged (Tab oldTab, Tab newTab) } /// - public override bool ProcessKey (KeyEvent keyEvent) + public override bool OnKeyPressed (KeyEventArgs arg) { if (HasFocus && CanFocus && Focused == tabsBar) { - var result = InvokeKeybindings (keyEvent); + var result = InvokeKeybindings (arg); if (result != null) return (bool)result; } - return base.ProcessKey (keyEvent); + return base.OnKeyPressed (arg); } /// diff --git a/Terminal.Gui/Views/TableView/TableView.cs b/Terminal.Gui/Views/TableView/TableView.cs index a5c25f3d43..7c414b0ef3 100644 --- a/Terminal.Gui/Views/TableView/TableView.cs +++ b/Terminal.Gui/Views/TableView/TableView.cs @@ -761,14 +761,14 @@ private string TruncateOrPad (object originalCellValue, string representation, i /// - public override bool ProcessKey (KeyEvent keyEvent) + public override bool OnKeyPressed (KeyEventArgs args) { if (TableIsNullOrInvisible ()) { PositionCursor (); return false; } - var result = InvokeKeybindings (keyEvent); + var result = InvokeKeybindings (args); if (result != null) { PositionCursor (); return true; @@ -777,17 +777,17 @@ public override bool ProcessKey (KeyEvent keyEvent) if (CollectionNavigator != null && this.HasFocus && Table.Rows != 0 && - Terminal.Gui.CollectionNavigator.IsCompatibleKey (keyEvent) && - !keyEvent.Key.HasFlag (Key.CtrlMask) && - !keyEvent.Key.HasFlag (Key.AltMask) && - char.IsLetterOrDigit ((char)keyEvent.KeyValue)) { - return CycleToNextTableEntryBeginningWith (keyEvent); + Terminal.Gui.CollectionNavigator.IsCompatibleKey (args) && + !args.Key.HasFlag (Key.CtrlMask) && + !args.Key.HasFlag (Key.AltMask) && + char.IsLetterOrDigit ((char)args.KeyValue)) { + return CycleToNextTableEntryBeginningWith (args); } return false; } - private bool CycleToNextTableEntryBeginningWith (KeyEvent keyEvent) + private bool CycleToNextTableEntryBeginningWith (KeyEventArgs keyEvent) { var row = SelectedRow; diff --git a/Terminal.Gui/Views/TableView/TreeTableSource.cs b/Terminal.Gui/Views/TableView/TreeTableSource.cs index 0b06691fd0..52c695085b 100644 --- a/Terminal.Gui/Views/TableView/TreeTableSource.cs +++ b/Terminal.Gui/Views/TableView/TreeTableSource.cs @@ -106,7 +106,7 @@ private string GetColumnZeroRepresentationFromTree (int row) return sb.ToString (); } - private void Table_KeyPress (object sender, KeyEventEventArgs e) + private void Table_KeyPress (object sender, KeyEventArgs e) { if (!IsInTreeColumn (_tableView.SelectedColumn, true)) { return; @@ -118,13 +118,13 @@ private void Table_KeyPress (object sender, KeyEventEventArgs e) return; } - if (e.KeyEvent.Key == Key.CursorLeft) { + if (e.Key == Key.CursorLeft) { if (_tree.IsExpanded (obj)) { _tree.Collapse (obj); e.Handled = true; } } - if (e.KeyEvent.Key == Key.CursorRight) { + if (e.Key == Key.CursorRight) { if (_tree.CanExpand (obj) && !_tree.IsExpanded (obj)) { _tree.Expand (obj); e.Handled = true; diff --git a/Terminal.Gui/Views/TextField.cs b/Terminal.Gui/Views/TextField.cs index 6ad4798d78..01bcb6b46c 100644 --- a/Terminal.Gui/Views/TextField.cs +++ b/Terminal.Gui/Views/TextField.cs @@ -637,7 +637,7 @@ void SetClipboard (IEnumerable text) /// /// /// - public override bool ProcessKey (KeyEvent kb) + public override bool OnKeyPressed (KeyEventArgs arg) { // remember current cursor position // because the new calculated cursor position is needed to be set BEFORE the change event is triggest @@ -645,28 +645,28 @@ public override bool ProcessKey (KeyEvent kb) _oldCursorPos = _point; // Give autocomplete first opportunity to respond to key presses - if (SelectedLength == 0 && Autocomplete.Suggestions.Count > 0 && Autocomplete.ProcessKey (kb)) { + if (SelectedLength == 0 && Autocomplete.Suggestions.Count > 0 && Autocomplete.ProcessKey (arg)) { return true; } - var result = InvokeKeybindings (new KeyEvent (ShortcutHelper.GetModifiersKey (kb), - new KeyModifiers () { Alt = kb.IsAlt, Ctrl = kb.IsCtrl, Shift = kb.IsShift })); + var result = InvokeKeybindings (new KeyEventArgs (ShortcutHelper.GetModifiersKey (arg), + new KeyModifiers () { Alt = arg.IsAlt, Ctrl = arg.IsCtrl, Shift = arg.IsShift })); if (result != null) return (bool)result; // Ignore other control characters. - if (kb.Key < Key.Space || kb.Key > Key.CharMask) + if (arg.Key < Key.Space || arg.Key > Key.CharMask) return false; if (ReadOnly) return true; - InsertText (kb); + InsertText (arg); return true; } - void InsertText (KeyEvent kb, bool useOldCursorPos = true) + void InsertText (KeyEventArgs kb, bool useOldCursorPos = true) { _historyText.Add (new List> () { TextModel.ToRuneCells (_text) }, new Point (_point, 0)); @@ -1312,7 +1312,7 @@ public void InsertText (string toAdd, bool useOldCursorPos = true) throw new ArgumentException ($"Cannot insert character '{ch}' because it does not map to a Key"); } - InsertText (new KeyEvent () { Key = key }, useOldCursorPos); + InsertText (new KeyEventArgs () { Key = key }, useOldCursorPos); } } diff --git a/Terminal.Gui/Views/TextValidateField.cs b/Terminal.Gui/Views/TextValidateField.cs index f687a82a5d..1107873505 100644 --- a/Terminal.Gui/Views/TextValidateField.cs +++ b/Terminal.Gui/Views/TextValidateField.cs @@ -612,7 +612,7 @@ bool EndKeyHandler () } /// - public override bool ProcessKey (KeyEvent kb) + public override bool OnKeyPressed (KeyEventArgs kb) { if (provider == null) { return false; diff --git a/Terminal.Gui/Views/TextView.cs b/Terminal.Gui/Views/TextView.cs index 3a746880bf..1e0ea2cde4 100644 --- a/Terminal.Gui/Views/TextView.cs +++ b/Terminal.Gui/Views/TextView.cs @@ -3065,7 +3065,7 @@ public void InsertText (string toAdd) throw new ArgumentException ($"Cannot insert character '{ch}' because it does not map to a Key"); } - InsertText (new KeyEvent () { Key = key }); + InsertText (new KeyEventArgs () { Key = key }); } if (NeedsDisplay) { @@ -3401,7 +3401,7 @@ public void ScrollTo (int idx, bool isRow = true) bool _shiftSelecting; /// - public override bool ProcessKey (KeyEvent kb) + public override bool OnKeyPressed (KeyEventArgs kb) { if (!CanFocus) { return true; @@ -3412,7 +3412,7 @@ public override bool ProcessKey (KeyEvent kb) return true; } - var result = InvokeKeybindings (new KeyEvent (ShortcutHelper.GetModifiersKey (kb), + var result = InvokeKeybindings (new KeyEventArgs (ShortcutHelper.GetModifiersKey (kb), new KeyModifiers () { Alt = kb.IsAlt, Ctrl = kb.IsCtrl, Shift = kb.IsShift })); if (result != null) return (bool)result; @@ -3791,7 +3791,7 @@ bool ProcessTab () if (!AllowsTab || _isReadOnly) { return ProcessMoveNextView (); } - InsertText (new KeyEvent ((Key)'\t', null)); + InsertText (new KeyEventArgs ((Key)'\t', null)); DoNeededAction (); return true; } @@ -4318,7 +4318,7 @@ void ResetAllTrack () _continuousFind = false; } - bool InsertText (KeyEvent kb, ColorScheme? colorScheme = null) + bool InsertText (KeyEventArgs kb, ColorScheme? colorScheme = null) { //So that special keys like tab can be processed if (_isReadOnly) @@ -4388,7 +4388,7 @@ public void DeleteAll () } /// - public override bool OnKeyUp (KeyEvent kb) + public override bool OnKeyUp (KeyEventArgs kb) { switch (kb.Key) { case Key.Space | Key.CtrlMask: diff --git a/Terminal.Gui/Views/TileView.cs b/Terminal.Gui/Views/TileView.cs index aa660203bc..a3b0f2dcc9 100644 --- a/Terminal.Gui/Views/TileView.cs +++ b/Terminal.Gui/Views/TileView.cs @@ -443,7 +443,7 @@ public bool TrySplitTile (int idx, int numberOfPanels, out TileView result) } /// - public override bool ProcessHotKey (KeyEvent keyEvent) + public override bool ProcessHotKey (KeyEventArgs keyEvent) { bool focusMoved = false; @@ -805,17 +805,17 @@ public TileViewLineView (TileView parent, int idx) AddKeyBinding (Key.CursorDown, Command.LineDown); } - public override bool ProcessKey (KeyEvent kb) + public override bool OnKeyPressed (KeyEventArgs kb) { if (!CanFocus || !HasFocus) { - return base.ProcessKey (kb); + return base.OnKeyPressed (kb); } var result = InvokeKeybindings (kb); if (result != null) return (bool)result; - return base.ProcessKey (kb); + return base.OnKeyPressed (kb); } public override void PositionCursor () diff --git a/Terminal.Gui/Views/TimeField.cs b/Terminal.Gui/Views/TimeField.cs index ff0b7198b8..e5944f1fc0 100644 --- a/Terminal.Gui/Views/TimeField.cs +++ b/Terminal.Gui/Views/TimeField.cs @@ -247,7 +247,7 @@ void AdjCursorPosition () } /// - public override bool ProcessKey (KeyEvent kb) + public override bool OnKeyPressed (KeyEventArgs kb) { var result = InvokeKeybindings (kb); if (result != null) diff --git a/Terminal.Gui/Views/Toplevel.cs b/Terminal.Gui/Views/Toplevel.cs index 4612d84cf0..a44b296c59 100644 --- a/Terminal.Gui/Views/Toplevel.cs +++ b/Terminal.Gui/Views/Toplevel.cs @@ -318,7 +318,7 @@ public override bool CanFocus { /// /// /// - /// events will propagate keys upwards. + /// events will propagate keys upwards. /// /// /// The Toplevel will act as an embedded view (not a modal/pop-up). @@ -329,7 +329,7 @@ public override bool CanFocus { /// /// /// - /// events will NOT propogate keys upwards. + /// events will NOT propogate keys upwards. /// /// /// The Toplevel will and look like a modal (pop-up) (e.g. see . @@ -355,7 +355,7 @@ public override bool CanFocus { public bool IsLoaded { get; private set; } /// - public override bool OnKeyDown (KeyEvent keyEvent) + public override bool OnKeyDown (KeyEventArgs keyEvent) { if (base.OnKeyDown (keyEvent)) { return true; @@ -373,7 +373,7 @@ public override bool OnKeyDown (KeyEvent keyEvent) } /// - public override bool OnKeyUp (KeyEvent keyEvent) + public override bool OnKeyUp (KeyEventArgs keyEvent) { if (base.OnKeyUp (keyEvent)) { return true; @@ -393,12 +393,12 @@ public override bool OnKeyUp (KeyEvent keyEvent) } /// - public override bool ProcessKey (KeyEvent keyEvent) + public override bool OnKeyPressed (KeyEventArgs keyEvent) { - if (base.ProcessKey (keyEvent)) + if (base.OnKeyPressed (keyEvent)) return true; - var result = InvokeKeybindings (new KeyEvent (ShortcutHelper.GetModifiersKey (keyEvent), + var result = InvokeKeybindings (new KeyEventArgs (ShortcutHelper.GetModifiersKey (keyEvent), new KeyModifiers () { Alt = keyEvent.IsAlt, Ctrl = keyEvent.IsCtrl, Shift = keyEvent.IsShift })); if (result != null) return (bool)result; @@ -479,7 +479,7 @@ private void QuitToplevel () } /// - public override bool ProcessColdKey (KeyEvent keyEvent) + public override bool ProcessColdKey (KeyEventArgs keyEvent) { if (base.ProcessColdKey (keyEvent)) { return true; diff --git a/Terminal.Gui/Views/TreeView/TreeView.cs b/Terminal.Gui/Views/TreeView/TreeView.cs index ba63944118..2180cad223 100644 --- a/Terminal.Gui/Views/TreeView/TreeView.cs +++ b/Terminal.Gui/Views/TreeView/TreeView.cs @@ -621,7 +621,7 @@ private IEnumerable> AddToLineMap (Branch currentBranch, bool paren public CollectionNavigator KeystrokeNavigator { get; private set; } = new CollectionNavigator (); /// - public override bool ProcessKey (KeyEvent keyEvent) + public override bool OnKeyPressed (KeyEventArgs arg) { if (!Enabled) { return false; @@ -629,13 +629,13 @@ public override bool ProcessKey (KeyEvent keyEvent) try { // First of all deal with any registered keybindings - var result = InvokeKeybindings (keyEvent); + var result = InvokeKeybindings (arg); if (result != null) { return (bool)result; } // If not a keybinding, is the key a searchable key press? - if (CollectionNavigator.IsCompatibleKey (keyEvent) && AllowLetterBasedNavigation) { + if (CollectionNavigator.IsCompatibleKey (arg) && AllowLetterBasedNavigation) { IReadOnlyCollection> map; // If there has been a call to InvalidateMap since the last time @@ -644,7 +644,7 @@ public override bool ProcessKey (KeyEvent keyEvent) // Find the current selected object within the tree var current = map.IndexOf (b => b.Model == SelectedObject); - var newIndex = KeystrokeNavigator?.GetNextMatchingItem (current, (char)keyEvent.KeyValue); + var newIndex = KeystrokeNavigator?.GetNextMatchingItem (current, (char)arg.KeyValue); if (newIndex is int && newIndex != -1) { SelectedObject = map.ElementAt ((int)newIndex).Model; @@ -657,7 +657,7 @@ public override bool ProcessKey (KeyEvent keyEvent) PositionCursor (); } - return base.ProcessKey (keyEvent); + return base.OnKeyPressed (arg); } /// diff --git a/Terminal.Gui/Views/Wizard/Wizard.cs b/Terminal.Gui/Views/Wizard/Wizard.cs index 8b8d0c89bd..b5b2627fa1 100644 --- a/Terminal.Gui/Views/Wizard/Wizard.cs +++ b/Terminal.Gui/Views/Wizard/Wizard.cs @@ -147,23 +147,23 @@ private void NextfinishBtn_Clicked (object sender, EventArgs e) /// /// is derived from and Dialog causes Esc to call - /// , closing the Dialog. Wizard overrides + /// , closing the Dialog. Wizard overrides /// to instead fire the event when Wizard is being used as a non-modal (see . - /// See for more. + /// See for more. /// /// /// - public override bool ProcessKey (KeyEvent kb) + public override bool OnKeyPressed (KeyEventArgs arg) { if (!Modal) { - switch (kb.Key) { + switch (arg.Key) { case Key.Esc: var args = new WizardButtonEventArgs (); Cancelled?.Invoke (this, args); return false; } } - return base.ProcessKey (kb); + return base.OnKeyPressed (arg); } /// diff --git a/UICatalog/KeyBindingsDialog.cs b/UICatalog/KeyBindingsDialog.cs index 538320f383..c4d65783ed 100644 --- a/UICatalog/KeyBindingsDialog.cs +++ b/UICatalog/KeyBindingsDialog.cs @@ -181,7 +181,7 @@ private void RemapKey (object sender, EventArgs e) // prompt user to hit a key var dlg = new Dialog () { Title = "Enter Key" }; dlg.KeyPressed += (s, k) => { - key = k.KeyEvent.Key; + key = k.Key; Application.RequestStop (); }; Application.Run (dlg); diff --git a/UICatalog/Scenarios/ASCIICustomButton.cs b/UICatalog/Scenarios/ASCIICustomButton.cs index eabde34c57..d57482a019 100644 --- a/UICatalog/Scenarios/ASCIICustomButton.cs +++ b/UICatalog/Scenarios/ASCIICustomButton.cs @@ -231,30 +231,30 @@ public ScrollViewTestWindow () } } - private void Button_KeyPress (object sender, KeyEventEventArgs obj) + private void Button_KeyPress (object sender, KeyEventArgs arg) { - switch (obj.KeyEvent.Key) { + switch (arg.Key) { case Key.End: scrollView.ContentOffset = new Point (scrollView.ContentOffset.X, -(scrollView.ContentSize.Height - scrollView.Frame.Height + (scrollView.ShowHorizontalScrollIndicator ? 1 : 0))); - obj.Handled = true; + arg.Handled = true; return; case Key.Home: scrollView.ContentOffset = new Point (scrollView.ContentOffset.X, 0); - obj.Handled = true; + arg.Handled = true; return; case Key.PageDown: scrollView.ContentOffset = new Point (scrollView.ContentOffset.X, Math.Max (scrollView.ContentOffset.Y - scrollView.Frame.Height, -(scrollView.ContentSize.Height - scrollView.Frame.Height + (scrollView.ShowHorizontalScrollIndicator ? 1 : 0)))); - obj.Handled = true; + arg.Handled = true; return; case Key.PageUp: scrollView.ContentOffset = new Point (scrollView.ContentOffset.X, Math.Min (scrollView.ContentOffset.Y + scrollView.Frame.Height, 0)); - obj.Handled = true; + arg.Handled = true; return; } } diff --git a/UICatalog/Scenarios/BackgroundWorkerCollection.cs b/UICatalog/Scenarios/BackgroundWorkerCollection.cs index 22434aaedf..7eb9dca533 100644 --- a/UICatalog/Scenarios/BackgroundWorkerCollection.cs +++ b/UICatalog/Scenarios/BackgroundWorkerCollection.cs @@ -339,7 +339,7 @@ public StagingUIController () Add (close); KeyPressed += (s, e) => { - if (e.KeyEvent.Key == Key.Esc) { + if (e.Key == Key.Esc) { OnReportClosed (this, EventArgs.Empty); } }; diff --git a/UICatalog/Scenarios/ContextMenus.cs b/UICatalog/Scenarios/ContextMenus.cs index c39cb248c6..2e0eaad8f3 100644 --- a/UICatalog/Scenarios/ContextMenus.cs +++ b/UICatalog/Scenarios/ContextMenus.cs @@ -59,7 +59,7 @@ public override void Setup () Point mousePos = default; Win.KeyPressed += (s, e) => { - if (e.KeyEvent.Key == (Key.Space | Key.CtrlMask)) { + if (e.Key == (Key.Space | Key.CtrlMask)) { ShowContextMenu (mousePos.X, mousePos.Y); e.Handled = true; } diff --git a/UICatalog/Scenarios/CsvEditor.cs b/UICatalog/Scenarios/CsvEditor.cs index 96ff667ffe..7c6b1deee1 100644 --- a/UICatalog/Scenarios/CsvEditor.cs +++ b/UICatalog/Scenarios/CsvEditor.cs @@ -465,9 +465,9 @@ private void SetupScrollBar () } - private void TableViewKeyPress (object sender, KeyEventEventArgs e) + private void TableViewKeyPress (object sender, KeyEventArgs e) { - if (e.KeyEvent.Key == Key.DeleteChar) { + if (e.Key == Key.DeleteChar) { if (tableView.FullRowSelect) { // Delete button deletes all rows when in full row mode diff --git a/UICatalog/Scenarios/DynamicMenuBar.cs b/UICatalog/Scenarios/DynamicMenuBar.cs index 62a8fcb80d..bb38a2d12c 100644 --- a/UICatalog/Scenarios/DynamicMenuBar.cs +++ b/UICatalog/Scenarios/DynamicMenuBar.cs @@ -723,17 +723,17 @@ public DynamicMenuBarDetails (string title) : base (title) ReadOnly = true }; _txtShortcut.KeyDown += (s, e) => { - if (!ProcessKey (e.KeyEvent)) { + if (!ProcessKey (e)) { return; } - var k = ShortcutHelper.GetModifiersKey (e.KeyEvent); + var k = ShortcutHelper.GetModifiersKey (e); if (CheckShortcut (k, true)) { e.Handled = true; } }; - bool ProcessKey (KeyEvent ev) + bool ProcessKey (KeyEventArgs ev) { switch (ev.Key) { case Key.CursorUp: @@ -766,7 +766,7 @@ bool CheckShortcut (Key k, bool pre) } _txtShortcut.KeyUp += (s, e) => { - var k = ShortcutHelper.GetModifiersKey (e.KeyEvent); + var k = ShortcutHelper.GetModifiersKey (e); if (CheckShortcut (k, false)) { e.Handled = true; } diff --git a/UICatalog/Scenarios/DynamicStatusBar.cs b/UICatalog/Scenarios/DynamicStatusBar.cs index e28092117a..1adf3bf1b9 100644 --- a/UICatalog/Scenarios/DynamicStatusBar.cs +++ b/UICatalog/Scenarios/DynamicStatusBar.cs @@ -396,17 +396,17 @@ public DynamicStatusBarDetails (string title) : base (title) ReadOnly = true }; _txtShortcut.KeyDown += (s, e) => { - if (!ProcessKey (e.KeyEvent)) { + if (!OnKeyPressed (e)) { return; } - var k = ShortcutHelper.GetModifiersKey (e.KeyEvent); + var k = ShortcutHelper.GetModifiersKey (e); if (CheckShortcut (k, true)) { e.Handled = true; } }; - bool ProcessKey (KeyEvent ev) + bool OnKeyPressed (KeyEventArgs ev) { switch (ev.Key) { case Key.CursorUp: @@ -440,7 +440,7 @@ bool CheckShortcut (Key k, bool pre) } _txtShortcut.KeyUp += (s, e) => { - var k = ShortcutHelper.GetModifiersKey (e.KeyEvent); + var k = ShortcutHelper.GetModifiersKey (e); if (CheckShortcut (k, false)) { e.Handled = true; } diff --git a/UICatalog/Scenarios/Editor.cs b/UICatalog/Scenarios/Editor.cs index 45c6f704fd..6b945f8bbc 100644 --- a/UICatalog/Scenarios/Editor.cs +++ b/UICatalog/Scenarios/Editor.cs @@ -177,11 +177,11 @@ public override void Init () }; Win.KeyPressed += (s, e) => { - var keys = ShortcutHelper.GetModifiersKey (e.KeyEvent); - if (_winDialog != null && (e.KeyEvent.Key == Key.Esc - || e.KeyEvent.Key == Application.QuitKey)) { + var keys = ShortcutHelper.GetModifiersKey (e); + if (_winDialog != null && (e.Key == Key.Esc + || e.Key == Application.QuitKey)) { DisposeWinDialog (); - } else if (e.KeyEvent.Key == Application.QuitKey) { + } else if (e.Key == Application.QuitKey) { Quit (); e.Handled = true; } else if (_winDialog != null && keys == (Key.Tab | Key.CtrlMask)) { diff --git a/UICatalog/Scenarios/InteractiveTree.cs b/UICatalog/Scenarios/InteractiveTree.cs index 26b26d1fde..6b2ba38812 100644 --- a/UICatalog/Scenarios/InteractiveTree.cs +++ b/UICatalog/Scenarios/InteractiveTree.cs @@ -44,9 +44,9 @@ public override void Setup () } - private void TreeView_KeyPress (object sender, KeyEventEventArgs obj) + private void TreeView_KeyPress (object sender, KeyEventArgs obj) { - if (obj.KeyEvent.Key == Key.DeleteChar) { + if (obj.Key == Key.DeleteChar) { var toDelete = treeView.SelectedObject; diff --git a/UICatalog/Scenarios/Keys.cs b/UICatalog/Scenarios/Keys.cs index 6594daa07c..e6373e625c 100644 --- a/UICatalog/Scenarios/Keys.cs +++ b/UICatalog/Scenarios/Keys.cs @@ -8,23 +8,23 @@ namespace UICatalog.Scenarios { public class Keys : Scenario { class TestWindow : Window { - public List _processKeyList = new List (); + public List _onKeyPressedList = new List (); public List _processHotKeyList = new List (); public List _processColdKeyList = new List (); - public override bool ProcessKey (KeyEvent keyEvent) + public override bool OnKeyPressed (KeyEventArgs arg) { - _processKeyList.Add (keyEvent.ToString ()); - return base.ProcessKey (keyEvent); + _onKeyPressedList.Add (arg.ToString ()); + return base.OnKeyPressed (arg); } - public override bool ProcessHotKey (KeyEvent keyEvent) + public override bool ProcessHotKey (KeyEventArgs keyEvent) { _processHotKeyList.Add (keyEvent.ToString ()); return base.ProcessHotKey (keyEvent); } - public override bool ProcessColdKey (KeyEvent keyEvent) + public override bool ProcessColdKey (KeyEventArgs keyEvent) { _processColdKeyList.Add (keyEvent.ToString ()); @@ -65,29 +65,30 @@ public override void Setup () Win.Add (edit); // Last KeyPress: ______ - var keyPressedLabel = new Label ("Last Application.KeyPress:") { + var appKeyPressedLabel = new Label ("Last Application.KeyPress:") { X = Pos.Left (editLabel), Y = Pos.Top (editLabel) + 2, }; - Win.Add (keyPressedLabel); - var labelKeypress = new Label ("") { - X = Pos.Left (edit), - Y = Pos.Top (keyPressedLabel), + Win.Add (appKeyPressedLabel); + var labelAppKeyPressed = new Label ("") { + X = Pos.Right (appKeyPressedLabel) + 1, + Y = Pos.Top (appKeyPressedLabel), TextAlignment = Terminal.Gui.TextAlignment.Centered, ColorScheme = Colors.Error, AutoSize = true }; - Win.Add (labelKeypress); + Win.Add (labelAppKeyPressed); - Win.KeyPressed += (s, e) => labelKeypress.Text = e.KeyEvent.ToString (); + Application.KeyPressed += (s, e) => labelAppKeyPressed.Text = e.ToString (); - // Key stroke log: - var keyLogLabel = new Label ("Key event log:") { + // Key event log (for Application): + + var keyLogLabel = new Label ("All events:") { X = Pos.Left (editLabel), Y = Pos.Top (editLabel) + 4, }; Win.Add (keyLogLabel); - var fakeKeyPress = new KeyEvent (Key.CtrlMask | Key.A, new KeyModifiers () { + var fakeKeyPress = new KeyEventArgs (Key.CtrlMask | Key.A, new KeyModifiers () { Alt = true, Ctrl = true, Shift = true @@ -105,7 +106,7 @@ public override void Setup () Win.Add (keyEventListView); // ProcessKey log: - var processKeyLogLabel = new Label ("ProcessKey log:") { + var processKeyLogLabel = new Label ("Win.OnKeyPressed:") { X = Pos.Right (keyEventListView) + 1, Y = Pos.Top (editLabel) + 4, }; @@ -113,7 +114,7 @@ public override void Setup () maxLogEntry = $"{fakeKeyPress}".Length; yOffset = (Application.Top == Application.Top ? 1 : 6); - var processKeyListView = new ListView (((TestWindow)Win)._processKeyList) { + var processKeyListView = new ListView (((TestWindow)Win)._onKeyPressedList) { X = Pos.Left (processKeyLogLabel), Y = Pos.Top (processKeyLogLabel) + yOffset, Width = Dim.Percent (30), @@ -124,7 +125,7 @@ public override void Setup () // ProcessHotKey log: // BUGBUG: Label is not positioning right with Pos, so using TextField instead - var processHotKeyLogLabel = new Label ("ProcessHotKey log:") { + var processHotKeyLogLabel = new Label ("Win.ProcessHotKey:") { X = Pos.Right (processKeyListView) + 1, Y = Pos.Top (editLabel) + 4, }; @@ -142,7 +143,7 @@ public override void Setup () // ProcessColdKey log: // BUGBUG: Label is not positioning right with Pos, so using TextField instead - var processColdKeyLogLabel = new Label ("ProcessColdKey log:") { + var processColdKeyLogLabel = new Label ("Win.ProcessColdKey:") { X = Pos.Right (processHotKeyListView) + 1, Y = Pos.Top (editLabel) + 4, }; @@ -156,14 +157,10 @@ public override void Setup () Height = Dim.Fill (), }; - Application.KeyDown += (s, a) => KeyDownPressUp (a, "Down"); - Application.KeyPressed += (s, a) => KeyDownPressUp (a, "Press"); - Application.KeyUp += (s, a) => KeyDownPressUp (a, "Up"); - - void KeyDownPressUp (KeyEventEventArgs args, string updown) + void KeyDownPressUp (KeyEventArgs args, string updown) { // BUGBUG: KeyEvent.ToString is badly broken - var msg = $"Key{updown,-5}: {args.KeyEvent}"; + var msg = $"Key{updown,-5}: {args}"; keyEventlist.Add (msg); keyEventListView.MoveDown (); processKeyListView.MoveDown (); @@ -171,6 +168,10 @@ void KeyDownPressUp (KeyEventEventArgs args, string updown) processHotKeyListView.MoveDown (); } + Application.KeyDown += (s, a) => KeyDownPressUp (a, "Down"); + Application.KeyPressed += (s, a) => KeyDownPressUp (a, "Press"); + Application.KeyUp += (s, a) => KeyDownPressUp (a, "Up"); + processColdKeyListView.ColorScheme = Colors.TopLevel; Win.Add (processColdKeyListView); } diff --git a/UICatalog/Scenarios/LineDrawing.cs b/UICatalog/Scenarios/LineDrawing.cs index 45de71facb..89a1812a1c 100644 --- a/UICatalog/Scenarios/LineDrawing.cs +++ b/UICatalog/Scenarios/LineDrawing.cs @@ -32,7 +32,7 @@ public override void Setup () Win.Add (canvas); Win.Add (tools); - Win.KeyPressed += (s,e) => { e.Handled = canvas.ProcessKey (e.KeyEvent); }; + Win.KeyPressed += (s,e) => { e.Handled = canvas.OnKeyPressed (e); }; } class ToolsView : Window { @@ -107,7 +107,7 @@ public DrawingArea () Stack undoHistory = new (); - public override bool ProcessKey (KeyEvent e) + public override bool OnKeyPressed (KeyEventArgs e) { if (e.Key == (Key.Z | Key.CtrlMask)) { var pop = _currentLayer.RemoveLastLine (); @@ -127,7 +127,7 @@ public override bool ProcessKey (KeyEvent e) } } - return base.ProcessKey (e); + return base.OnKeyPressed (e); } internal void AddLayer () { diff --git a/UICatalog/Scenarios/ListColumns.cs b/UICatalog/Scenarios/ListColumns.cs index c3c38f0695..bb5484d07f 100644 --- a/UICatalog/Scenarios/ListColumns.cs +++ b/UICatalog/Scenarios/ListColumns.cs @@ -153,9 +153,9 @@ private void SetupScrollBar () } - private void TableViewKeyPress (object sender, KeyEventEventArgs e) + private void TableViewKeyPress (object sender, KeyEventArgs e) { - if (e.KeyEvent.Key == Key.DeleteChar) { + if (e.Key == Key.DeleteChar) { // set all selected cells to null foreach (var pt in listColView.GetAllSelectedCells ()) { diff --git a/UICatalog/Scenarios/SendKeys.cs b/UICatalog/Scenarios/SendKeys.cs index dd9eef8ddd..965fb30c80 100644 --- a/UICatalog/Scenarios/SendKeys.cs +++ b/UICatalog/Scenarios/SendKeys.cs @@ -58,16 +58,16 @@ public override void Setup () var IsCtrl = false; txtResult.KeyPressed += (s, e) => { - rKeys += (char)e.KeyEvent.Key; - if (!IsShift && e.KeyEvent.IsShift) { + rKeys += (char)e.Key; + if (!IsShift && e.IsShift) { rControlKeys += " Shift "; IsShift = true; } - if (!IsAlt && e.KeyEvent.IsAlt) { + if (!IsAlt && e.IsAlt) { rControlKeys += " Alt "; IsAlt = true; } - if (!IsCtrl && e.KeyEvent.IsCtrl) { + if (!IsCtrl && e.IsCtrl) { rControlKeys += " Ctrl "; IsCtrl = true; } @@ -117,7 +117,7 @@ void ProcessInput () button.Clicked += (s,e) => ProcessInput (); Win.KeyPressed += (s, e) => { - if (e.KeyEvent.Key == Key.Enter) { + if (e.Key == Key.Enter) { ProcessInput (); e.Handled = true; } diff --git a/UICatalog/Scenarios/SingleBackgroundWorker.cs b/UICatalog/Scenarios/SingleBackgroundWorker.cs index 80b3693e65..d979f34b4a 100644 --- a/UICatalog/Scenarios/SingleBackgroundWorker.cs +++ b/UICatalog/Scenarios/SingleBackgroundWorker.cs @@ -136,7 +136,7 @@ public StagingUIController (DateTime? start, List list) top.KeyPressed += (s,e) => { // Prevents Ctrl+Q from closing this. // Only Ctrl+C is allowed. - if (e.KeyEvent.Key == Application.QuitKey) { + if (e.Key == Application.QuitKey) { e.Handled = true; } }; diff --git a/UICatalog/Scenarios/Snake.cs b/UICatalog/Scenarios/Snake.cs index 327480ba8c..1c9d786c7e 100644 --- a/UICatalog/Scenarios/Snake.cs +++ b/UICatalog/Scenarios/Snake.cs @@ -124,7 +124,7 @@ public override void OnDrawContent (Rect contentArea) AddRune (State.Apple.X, State.Apple.Y, _appleRune); Driver.SetAttribute (white); } - public override bool OnKeyDown (KeyEvent keyEvent) + public override bool OnKeyDown (KeyEventArgs keyEvent) { if (keyEvent.Key == Key.CursorUp) { State.PlannedDirection = Direction.Up; diff --git a/UICatalog/Scenarios/TableEditor.cs b/UICatalog/Scenarios/TableEditor.cs index bf477e8eac..4de2a7ce41 100644 --- a/UICatalog/Scenarios/TableEditor.cs +++ b/UICatalog/Scenarios/TableEditor.cs @@ -386,13 +386,13 @@ private void SetupScrollBar () } - private void TableViewKeyPress (object sender, KeyEventEventArgs e) + private void TableViewKeyPress (object sender, KeyEventArgs e) { if(currentTable == null) { return; } - if (e.KeyEvent.Key == Key.DeleteChar) { + if (e.Key == Key.DeleteChar) { if (tableView.FullRowSelect) { // Delete button deletes all rows when in full row mode diff --git a/UICatalog/Scenarios/TreeViewFileSystem.cs b/UICatalog/Scenarios/TreeViewFileSystem.cs index 7e4c722426..a9517ca915 100644 --- a/UICatalog/Scenarios/TreeViewFileSystem.cs +++ b/UICatalog/Scenarios/TreeViewFileSystem.cs @@ -158,9 +158,9 @@ private void TreeViewFiles_DrawLine (object sender, DrawTreeViewLineEventArgs { - //System.Diagnostics.Debug.WriteLine ($"Output - KeyDown: {e.KeyEvent.Key}"); + //System.Diagnostics.Debug.WriteLine ($"Output - KeyDown: {e.Key}"); e.Handled = true; - if (e.KeyEvent.Key == Key.Unknown) { + if (e.Key == Key.Unknown) { _wasUnknown = true; } }; @@ -99,9 +99,9 @@ public override void Setup () tvOutput.KeyPressed += (s, e) => { //System.Diagnostics.Debug.WriteLine ($"Output - KeyPress - _keyboardStrokes: {_keyboardStrokes.Count}"); if (_outputStarted && _keyboardStrokes.Count > 0) { - var ev = ShortcutHelper.GetModifiersKey (e.KeyEvent); + var ev = ShortcutHelper.GetModifiersKey (e); //System.Diagnostics.Debug.WriteLine ($"Output - KeyPress: {ev}"); - if (!tvOutput.ProcessKey (e.KeyEvent)) { + if (!tvOutput.OnKeyPressed (e)) { Application.Invoke (() => { MessageBox.Query ("Keys", $"'{ShortcutHelper.GetShortcutTag (ev)}' pressed!", "Ok"); }); @@ -115,28 +115,28 @@ public override void Setup () Win.Add (tvOutput); tvInput.KeyDown += (s, e) => { - //System.Diagnostics.Debug.WriteLine ($"Input - KeyDown: {e.KeyEvent.Key}"); + //System.Diagnostics.Debug.WriteLine ($"Input - KeyDown: {e.Key}"); e.Handled = true; - if (e.KeyEvent.Key == Key.Unknown) { + if (e.Key == Key.Unknown) { _wasUnknown = true; } }; - KeyEventEventArgs unknownChar = null; + KeyEventArgs unknownChar = null; tvInput.KeyPressed += (s, e) => { - if (e.KeyEvent.Key == (Key.Q | Key.CtrlMask)) { + if (e.Key == (Key.Q | Key.CtrlMask)) { Application.RequestStop (); return; } - if (e.KeyEvent.Key == Key.Unknown) { + if (e.Key == Key.Unknown) { _wasUnknown = true; e.Handled = true; return; } if (_wasUnknown && _keyboardStrokes.Count == 1) { _wasUnknown = false; - } else if (_wasUnknown && char.IsLetter ((char)e.KeyEvent.Key)) { + } else if (_wasUnknown && char.IsLetter ((char)e.Key)) { _wasUnknown = false; } else if (!_wasUnknown && _keyboardStrokes.Count > 0) { e.Handled = true; @@ -147,15 +147,15 @@ public override void Setup () } else { _keyboardStrokes.Insert (0, 0); } - var ev = ShortcutHelper.GetModifiersKey (e.KeyEvent); + var ev = ShortcutHelper.GetModifiersKey (e); //System.Diagnostics.Debug.WriteLine ($"Input - KeyPress: {ev}"); //System.Diagnostics.Debug.WriteLine ($"Input - KeyPress - _keyboardStrokes: {_keyboardStrokes.Count}"); }; tvInput.KeyUp += (s, e) => { - //System.Diagnostics.Debug.WriteLine ($"Input - KeyUp: {e.KeyEvent.Key}"); + //System.Diagnostics.Debug.WriteLine ($"Input - KeyUp: {e.Key}"); //var ke = e.KeyEvent; - var ke = ShortcutHelper.GetModifiersKey (e.KeyEvent); + var ke = ShortcutHelper.GetModifiersKey (e); if (_wasUnknown && (int)ke - (int)(ke & (Key.AltMask | Key.CtrlMask | Key.ShiftMask)) != 0) { unknownChar = e; } @@ -232,21 +232,20 @@ void Win_LayoutComplete (object sender, LayoutEventArgs obj) Win.LayoutComplete += Win_LayoutComplete; } - private void AddKeyboardStrokes (KeyEventEventArgs e) + private void AddKeyboardStrokes (KeyEventArgs e) { - var ke = e.KeyEvent; var km = new KeyModifiers (); - if (ke.IsShift) { + if (e.IsShift) { km.Shift = true; } - if (ke.IsAlt) { + if (e.IsAlt) { km.Alt = true; } - if (ke.IsCtrl) { + if (e.IsCtrl) { km.Ctrl = true; } - var keyChar = ke.KeyValue; - var mK = (int)((Key)ke.KeyValue & (Key.AltMask | Key.CtrlMask | Key.ShiftMask)); + var keyChar = e.KeyValue; + var mK = (int)((Key)e.KeyValue & (Key.AltMask | Key.CtrlMask | Key.ShiftMask)); keyChar &= ~mK; _keyboardStrokes.Add (keyChar); } diff --git a/UICatalog/UICatalog.cs b/UICatalog/UICatalog.cs index 73df8a21b8..3d8bfe0d04 100644 --- a/UICatalog/UICatalog.cs +++ b/UICatalog/UICatalog.cs @@ -373,8 +373,8 @@ public UICatalogTopLevel () // TableView does not (currently) have built-in CollectionNavigator support (the ability for the // user to type and the items that match get selected). We implement it in the app instead. ScenarioList.KeyDown += (s, a) => { - if (CollectionNavigator.IsCompatibleKey (a.KeyEvent)) { - var newItem = _scenarioCollectionNav?.GetNextMatchingItem (ScenarioList.SelectedRow, (char)a.KeyEvent.KeyValue); + if (CollectionNavigator.IsCompatibleKey (a)) { + var newItem = _scenarioCollectionNav?.GetNextMatchingItem (ScenarioList.SelectedRow, (char)a.KeyValue); if (newItem is int v && newItem != -1) { ScenarioList.SelectedRow = v; ScenarioList.EnsureSelectedCellIsVisible (); @@ -768,9 +768,9 @@ public void ConfigChanged () Application.Top.SetNeedsDisplay (); } - void KeyDownHandler (object? sender, KeyEventEventArgs? a) + void KeyDownHandler (object? sender, KeyEventArgs? a) { - if (a!.KeyEvent.IsCapslock) { + if (a!.IsCapslock) { Capslock.Title = "Caps: On"; StatusBar.SetNeedsDisplay (); } else { @@ -778,7 +778,7 @@ void KeyDownHandler (object? sender, KeyEventEventArgs? a) StatusBar.SetNeedsDisplay (); } - if (a!.KeyEvent.IsNumlock) { + if (a!.IsNumlock) { Numlock.Title = "Num: On"; StatusBar.SetNeedsDisplay (); } else { @@ -786,7 +786,7 @@ void KeyDownHandler (object? sender, KeyEventEventArgs? a) StatusBar.SetNeedsDisplay (); } - if (a!.KeyEvent.IsScrolllock) { + if (a!.IsScrolllock) { Scrolllock.Title = "Scroll: On"; StatusBar.SetNeedsDisplay (); } else { diff --git a/UnitTests/Application/ApplicationTests.cs b/UnitTests/Application/ApplicationTests.cs index 5dca0018c8..80d6eb6635 100644 --- a/UnitTests/Application/ApplicationTests.cs +++ b/UnitTests/Application/ApplicationTests.cs @@ -582,9 +582,9 @@ public void KeyUp_Event () int keyUps = 0; var output = string.Empty; - Application.Top.KeyUp += (object sender, KeyEventEventArgs args) => { - if (args.KeyEvent.Key != (Key.CtrlMask | Key.Q)) { - output += (char)args.KeyEvent.KeyValue; + Application.Top.KeyUp += (object sender, KeyEventArgs args) => { + if (args.Key != (Key.CtrlMask | Key.Q)) { + output += (char)args.KeyValue; } keyUps++; }; @@ -631,55 +631,55 @@ public void AlternateForwardKey_AlternateBackwardKey_Tests () Application.Iteration += (s, a) => { Assert.True (v1.HasFocus); // Using default keys. - top.ProcessKey (new KeyEvent (Key.CtrlMask | Key.Tab, + top.OnKeyPressed (new KeyEventArgs (Key.CtrlMask | Key.Tab, new KeyModifiers () { Ctrl = true })); Assert.True (v2.HasFocus); - top.ProcessKey (new KeyEvent (Key.CtrlMask | Key.Tab, + top.OnKeyPressed (new KeyEventArgs (Key.CtrlMask | Key.Tab, new KeyModifiers () { Ctrl = true })); Assert.True (v3.HasFocus); - top.ProcessKey (new KeyEvent (Key.CtrlMask | Key.Tab, + top.OnKeyPressed (new KeyEventArgs (Key.CtrlMask | Key.Tab, new KeyModifiers () { Ctrl = true })); Assert.True (v4.HasFocus); - top.ProcessKey (new KeyEvent (Key.CtrlMask | Key.Tab, + top.OnKeyPressed (new KeyEventArgs (Key.CtrlMask | Key.Tab, new KeyModifiers () { Ctrl = true })); Assert.True (v1.HasFocus); - top.ProcessKey (new KeyEvent (Key.ShiftMask | Key.CtrlMask | Key.Tab, + top.OnKeyPressed (new KeyEventArgs (Key.ShiftMask | Key.CtrlMask | Key.Tab, new KeyModifiers () { Shift = true, Ctrl = true })); Assert.True (v4.HasFocus); - top.ProcessKey (new KeyEvent (Key.ShiftMask | Key.CtrlMask | Key.Tab, + top.OnKeyPressed (new KeyEventArgs (Key.ShiftMask | Key.CtrlMask | Key.Tab, new KeyModifiers () { Shift = true, Ctrl = true })); Assert.True (v3.HasFocus); - top.ProcessKey (new KeyEvent (Key.ShiftMask | Key.CtrlMask | Key.Tab, + top.OnKeyPressed (new KeyEventArgs (Key.ShiftMask | Key.CtrlMask | Key.Tab, new KeyModifiers () { Shift = true, Ctrl = true })); Assert.True (v2.HasFocus); - top.ProcessKey (new KeyEvent (Key.ShiftMask | Key.CtrlMask | Key.Tab, + top.OnKeyPressed (new KeyEventArgs (Key.ShiftMask | Key.CtrlMask | Key.Tab, new KeyModifiers () { Shift = true, Ctrl = true })); Assert.True (v1.HasFocus); - top.ProcessKey (new KeyEvent (Key.CtrlMask | Key.PageDown, + top.OnKeyPressed (new KeyEventArgs (Key.CtrlMask | Key.PageDown, new KeyModifiers () { Ctrl = true })); Assert.True (v2.HasFocus); - top.ProcessKey (new KeyEvent (Key.CtrlMask | Key.PageDown, + top.OnKeyPressed (new KeyEventArgs (Key.CtrlMask | Key.PageDown, new KeyModifiers () { Ctrl = true })); Assert.True (v3.HasFocus); - top.ProcessKey (new KeyEvent (Key.CtrlMask | Key.PageDown, + top.OnKeyPressed (new KeyEventArgs (Key.CtrlMask | Key.PageDown, new KeyModifiers () { Ctrl = true })); Assert.True (v4.HasFocus); - top.ProcessKey (new KeyEvent (Key.CtrlMask | Key.PageDown, + top.OnKeyPressed (new KeyEventArgs (Key.CtrlMask | Key.PageDown, new KeyModifiers () { Ctrl = true })); Assert.True (v1.HasFocus); - top.ProcessKey (new KeyEvent (Key.CtrlMask | Key.PageUp, + top.OnKeyPressed (new KeyEventArgs (Key.CtrlMask | Key.PageUp, new KeyModifiers () { Ctrl = true })); Assert.True (v4.HasFocus); - top.ProcessKey (new KeyEvent (Key.CtrlMask | Key.PageUp, + top.OnKeyPressed (new KeyEventArgs (Key.CtrlMask | Key.PageUp, new KeyModifiers () { Ctrl = true })); Assert.True (v3.HasFocus); - top.ProcessKey (new KeyEvent (Key.CtrlMask | Key.PageUp, + top.OnKeyPressed (new KeyEventArgs (Key.CtrlMask | Key.PageUp, new KeyModifiers () { Ctrl = true })); Assert.True (v2.HasFocus); - top.ProcessKey (new KeyEvent (Key.CtrlMask | Key.PageUp, + top.OnKeyPressed (new KeyEventArgs (Key.CtrlMask | Key.PageUp, new KeyModifiers () { Ctrl = true })); Assert.True (v1.HasFocus); @@ -687,22 +687,22 @@ public void AlternateForwardKey_AlternateBackwardKey_Tests () Application.AlternateForwardKey = Key.F7; Application.AlternateBackwardKey = Key.F6; - top.ProcessKey (new KeyEvent (Key.F7, new KeyModifiers ())); + top.OnKeyPressed (new KeyEventArgs (Key.F7, new KeyModifiers ())); Assert.True (v2.HasFocus); - top.ProcessKey (new KeyEvent (Key.F7, new KeyModifiers ())); + top.OnKeyPressed (new KeyEventArgs (Key.F7, new KeyModifiers ())); Assert.True (v3.HasFocus); - top.ProcessKey (new KeyEvent (Key.F7, new KeyModifiers ())); + top.OnKeyPressed (new KeyEventArgs (Key.F7, new KeyModifiers ())); Assert.True (v4.HasFocus); - top.ProcessKey (new KeyEvent (Key.F7, new KeyModifiers ())); + top.OnKeyPressed (new KeyEventArgs (Key.F7, new KeyModifiers ())); Assert.True (v1.HasFocus); - top.ProcessKey (new KeyEvent (Key.F6, new KeyModifiers ())); + top.OnKeyPressed (new KeyEventArgs (Key.F6, new KeyModifiers ())); Assert.True (v4.HasFocus); - top.ProcessKey (new KeyEvent (Key.F6, new KeyModifiers ())); + top.OnKeyPressed (new KeyEventArgs (Key.F6, new KeyModifiers ())); Assert.True (v3.HasFocus); - top.ProcessKey (new KeyEvent (Key.F6, new KeyModifiers ())); + top.OnKeyPressed (new KeyEventArgs (Key.F6, new KeyModifiers ())); Assert.True (v2.HasFocus); - top.ProcessKey (new KeyEvent (Key.F6, new KeyModifiers ())); + top.OnKeyPressed (new KeyEventArgs (Key.F6, new KeyModifiers ())); Assert.True (v1.HasFocus); Application.RequestStop (); @@ -775,14 +775,14 @@ public void EnsuresTopOnFront_CanFocus_True_By_Keyboard_And_Mouse () Assert.False (win2.HasFocus); Assert.Equal ("win2", ((Window)top.Subviews [top.Subviews.Count - 1]).Title); - top.ProcessKey (new KeyEvent (Key.CtrlMask | Key.Tab, new KeyModifiers ())); + top.OnKeyPressed (new KeyEventArgs (Key.CtrlMask | Key.Tab, new KeyModifiers ())); Assert.True (win.CanFocus); Assert.False (win.HasFocus); Assert.True (win2.CanFocus); Assert.True (win2.HasFocus); Assert.Equal ("win2", ((Window)top.Subviews [top.Subviews.Count - 1]).Title); - top.ProcessKey (new KeyEvent (Key.CtrlMask | Key.Tab, new KeyModifiers ())); + top.OnKeyPressed (new KeyEventArgs (Key.CtrlMask | Key.Tab, new KeyModifiers ())); Assert.True (win.CanFocus); Assert.True (win.HasFocus); Assert.True (win2.CanFocus); @@ -827,14 +827,14 @@ public void EnsuresTopOnFront_CanFocus_False_By_Keyboard_And_Mouse () Assert.True (win2.HasFocus); Assert.Equal ("win2", ((Window)top.Subviews [top.Subviews.Count - 1]).Title); - top.ProcessKey (new KeyEvent (Key.CtrlMask | Key.Tab, new KeyModifiers ())); + top.OnKeyPressed (new KeyEventArgs (Key.CtrlMask | Key.Tab, new KeyModifiers ())); Assert.True (win2.CanFocus); Assert.False (win.HasFocus); Assert.True (win2.CanFocus); Assert.True (win2.HasFocus); Assert.Equal ("win2", ((Window)top.Subviews [top.Subviews.Count - 1]).Title); - top.ProcessKey (new KeyEvent (Key.CtrlMask | Key.Tab, new KeyModifiers ())); + top.OnKeyPressed (new KeyEventArgs (Key.CtrlMask | Key.Tab, new KeyModifiers ())); Assert.False (win.CanFocus); Assert.False (win.HasFocus); Assert.True (win2.CanFocus); diff --git a/UnitTests/Application/MainLoopTests.cs b/UnitTests/Application/MainLoopTests.cs index a3cba7a4e7..1dd7c6ff46 100644 --- a/UnitTests/Application/MainLoopTests.cs +++ b/UnitTests/Application/MainLoopTests.cs @@ -688,7 +688,7 @@ public void Mainloop_Invoke_Or_AddIdle_Can_Be_Used_For_Events_Or_Actions (Action if (iterations == 0) { Assert.Null (btn); Assert.Equal (zero, total); - Assert.True (btnLaunch.ProcessKey (new KeyEvent (Key.Enter, null))); + Assert.True (btnLaunch.OnKeyPressed (new KeyEventArgs (Key.Enter, null))); if (btn == null) { Assert.Null (btn); Assert.Equal (zero, total); @@ -699,7 +699,7 @@ public void Mainloop_Invoke_Or_AddIdle_Can_Be_Used_For_Events_Or_Actions (Action } else if (iterations == 1) { Assert.Equal (clickMe, btn.Text); Assert.Equal (zero, total); - Assert.True (btn.ProcessKey (new KeyEvent (Key.Enter, null))); + Assert.True (btn.OnKeyPressed (new KeyEventArgs (Key.Enter, null))); Assert.Equal (cancel, btn.Text); Assert.Equal (one, total); } else if (taskCompleted) { diff --git a/UnitTests/ConsoleDrivers/ConsoleDriverTests.cs b/UnitTests/ConsoleDrivers/ConsoleDriverTests.cs index f36a550b13..8675953355 100644 --- a/UnitTests/ConsoleDrivers/ConsoleDriverTests.cs +++ b/UnitTests/ConsoleDrivers/ConsoleDriverTests.cs @@ -121,8 +121,8 @@ public void FakeDriver_MockKeyPresses (Type driverType) var idx = 0; view.KeyPressed += (s, e) => { - Assert.Equal (text [idx], (char)e.KeyEvent.Key); - rText += (char)e.KeyEvent.Key; + Assert.Equal (text [idx], (char)e.Key); + rText += (char)e.Key; Assert.Equal (rText, text.Substring (0, idx + 1)); e.Handled = true; idx++; @@ -175,7 +175,7 @@ public void FakeDriver_MockKeyPresses (Type driverType) // Key key = Key.Unknown; // Application.Top.KeyPress += (e) => { - // key = e.KeyEvent.Key; + // key = e.Key; // output.WriteLine ($" Application.Top.KeyPress: {key}"); // e.Handled = true; @@ -258,7 +258,7 @@ public void TerminalResized_Simulation (Type driverType) // var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output); // Assert.Equal (new Rect (0, 0, 20, 8), pos); -// Assert.True (dlg.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ()))); +// Assert.True (dlg.ProcessKey (new KeyEventArgs (Key.Tab, new KeyModifiers ()))); // dlg.Draw (); // expected = @" diff --git a/UnitTests/ConsoleDrivers/KeyTests.cs b/UnitTests/ConsoleDrivers/KeyTests.cs index b7ad45b28c..54d0964665 100644 --- a/UnitTests/ConsoleDrivers/KeyTests.cs +++ b/UnitTests/ConsoleDrivers/KeyTests.cs @@ -209,7 +209,7 @@ public void TestVKPacket (uint unicodeCharacter, bool shift, bool alt, bool cont var top = Application.Top; top.KeyPressed += (s, e) => { - var after = ShortcutHelper.GetModifiersKey (e.KeyEvent); + var after = ShortcutHelper.GetModifiersKey (e); Assert.Equal (expectedRemapping, after); e.Handled = true; Application.RequestStop (); diff --git a/UnitTests/Dialogs/DialogTests.cs b/UnitTests/Dialogs/DialogTests.cs index e01885ef9b..3c1695a5f4 100644 --- a/UnitTests/Dialogs/DialogTests.cs +++ b/UnitTests/Dialogs/DialogTests.cs @@ -799,7 +799,7 @@ public void Dialog_Opened_From_Another_Dialog () Application.Iteration += (s, a) => { iterations++; if (iterations == 0) { - Assert.True (btn1.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ()))); + Assert.True (btn1.OnKeyPressed (new KeyEventArgs (Key.Enter, new KeyModifiers ()))); } else if (iterations == 1) { expected = @$" ┌──────────────────────────────────────────────────────────────────┐ @@ -825,7 +825,7 @@ public void Dialog_Opened_From_Another_Dialog () └──────────────────────────────────────────────────────────────────┘"; TestHelpers.AssertDriverContentsWithFrameAre (expected, output); - Assert.True (btn2.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ()))); + Assert.True (btn2.OnKeyPressed (new KeyEventArgs (Key.Enter, new KeyModifiers ()))); } else if (iterations == 2) { TestHelpers.AssertDriverContentsWithFrameAre (@$" ┌──────────────────────────────────────────────────────────────────┐ @@ -850,11 +850,11 @@ public void Dialog_Opened_From_Another_Dialog () │ {CM.Glyphs.LeftBracket} Show Sub {CM.Glyphs.RightBracket} {CM.Glyphs.LeftBracket} Close {CM.Glyphs.RightBracket} │ └──────────────────────────────────────────────────────────────────┘", output); - Assert.True (Application.Current.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ()))); + Assert.True (Application.Current.OnKeyPressed (new KeyEventArgs (Key.Enter, new KeyModifiers ()))); } else if (iterations == 3) { TestHelpers.AssertDriverContentsWithFrameAre (expected, output); - Assert.True (btn3.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ()))); + Assert.True (btn3.OnKeyPressed (new KeyEventArgs (Key.Enter, new KeyModifiers ()))); } else if (iterations == 4) { TestHelpers.AssertDriverContentsWithFrameAre ("", output); diff --git a/UnitTests/Input/ResponderTests.cs b/UnitTests/Input/ResponderTests.cs index d060db42f5..72407386d5 100644 --- a/UnitTests/Input/ResponderTests.cs +++ b/UnitTests/Input/ResponderTests.cs @@ -23,11 +23,11 @@ public void New_Methods_Return_False () { var r = new Responder (); - Assert.False (r.ProcessKey (new KeyEvent () { Key = Key.Unknown })); - Assert.False (r.ProcessHotKey (new KeyEvent () { Key = Key.Unknown })); - Assert.False (r.ProcessColdKey (new KeyEvent () { Key = Key.Unknown })); - Assert.False (r.OnKeyDown (new KeyEvent () { Key = Key.Unknown })); - Assert.False (r.OnKeyUp (new KeyEvent () { Key = Key.Unknown })); + Assert.False (r.OnKeyPressed (new KeyEventArgs () { Key = Key.Unknown })); + Assert.False (r.ProcessHotKey (new KeyEventArgs () { Key = Key.Unknown })); + Assert.False (r.ProcessColdKey (new KeyEventArgs () { Key = Key.Unknown })); + Assert.False (r.OnKeyDown (new KeyEventArgs () { Key = Key.Unknown })); + Assert.False (r.OnKeyUp (new KeyEventArgs () { Key = Key.Unknown })); Assert.False (r.MouseEvent (new MouseEvent () { Flags = MouseFlags.AllEvents })); Assert.False (r.OnMouseEnter (new MouseEvent () { Flags = MouseFlags.AllEvents })); Assert.False (r.OnMouseLeave (new MouseEvent () { Flags = MouseFlags.AllEvents })); @@ -62,7 +62,7 @@ public DerivedView () { } - public override bool OnKeyDown (KeyEvent keyEvent) + public override bool OnKeyDown (KeyEventArgs keyEvent) { return true; } diff --git a/UnitTests/Text/AutocompleteTests.cs b/UnitTests/Text/AutocompleteTests.cs index dcf909fc8f..bd4233ad86 100644 --- a/UnitTests/Text/AutocompleteTests.cs +++ b/UnitTests/Text/AutocompleteTests.cs @@ -92,7 +92,7 @@ public void KeyBindings_Command () Assert.Equal ("feature", g.AllSuggestions [^1]); Assert.Equal (0, tv.Autocomplete.SelectedIdx); Assert.Empty (tv.Autocomplete.Suggestions); - Assert.True (tv.ProcessKey (new KeyEvent (Key.F, new KeyModifiers ()))); + Assert.True (tv.OnKeyPressed (new KeyEventArgs (Key.F, new KeyModifiers ()))); top.Draw (); Assert.Equal ($"F Fortunately super feature.", tv.Text); Assert.Equal (new Point (1, 0), tv.CursorPosition); @@ -101,7 +101,7 @@ public void KeyBindings_Command () Assert.Equal ("feature", tv.Autocomplete.Suggestions [^1].Replacement); Assert.Equal (0, tv.Autocomplete.SelectedIdx); Assert.Equal ("Fortunately", tv.Autocomplete.Suggestions [tv.Autocomplete.SelectedIdx].Replacement); - Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorDown, new KeyModifiers ()))); + Assert.True (tv.OnKeyPressed (new KeyEventArgs (Key.CursorDown, new KeyModifiers ()))); top.Draw (); Assert.Equal ($"F Fortunately super feature.", tv.Text); Assert.Equal (new Point (1, 0), tv.CursorPosition); @@ -110,7 +110,7 @@ public void KeyBindings_Command () Assert.Equal ("feature", tv.Autocomplete.Suggestions [^1].Replacement); Assert.Equal (1, tv.Autocomplete.SelectedIdx); Assert.Equal ("feature", tv.Autocomplete.Suggestions [tv.Autocomplete.SelectedIdx].Replacement); - Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorDown, new KeyModifiers ()))); + Assert.True (tv.OnKeyPressed (new KeyEventArgs (Key.CursorDown, new KeyModifiers ()))); top.Draw (); Assert.Equal ($"F Fortunately super feature.", tv.Text); Assert.Equal (new Point (1, 0), tv.CursorPosition); @@ -119,7 +119,7 @@ public void KeyBindings_Command () Assert.Equal ("feature", tv.Autocomplete.Suggestions [^1].Replacement); Assert.Equal (0, tv.Autocomplete.SelectedIdx); Assert.Equal ("Fortunately", tv.Autocomplete.Suggestions [tv.Autocomplete.SelectedIdx].Replacement); - Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorUp, new KeyModifiers ()))); + Assert.True (tv.OnKeyPressed (new KeyEventArgs (Key.CursorUp, new KeyModifiers ()))); top.Draw (); Assert.Equal ($"F Fortunately super feature.", tv.Text); Assert.Equal (new Point (1, 0), tv.CursorPosition); @@ -128,7 +128,7 @@ public void KeyBindings_Command () Assert.Equal ("feature", tv.Autocomplete.Suggestions [^1].Replacement); Assert.Equal (1, tv.Autocomplete.SelectedIdx); Assert.Equal ("feature", tv.Autocomplete.Suggestions [tv.Autocomplete.SelectedIdx].Replacement); - Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorUp, new KeyModifiers ()))); + Assert.True (tv.OnKeyPressed (new KeyEventArgs (Key.CursorUp, new KeyModifiers ()))); top.Draw (); Assert.Equal ($"F Fortunately super feature.", tv.Text); Assert.Equal (new Point (1, 0), tv.CursorPosition); @@ -139,19 +139,19 @@ public void KeyBindings_Command () Assert.Equal ("Fortunately", tv.Autocomplete.Suggestions [tv.Autocomplete.SelectedIdx].Replacement); Assert.True (tv.Autocomplete.Visible); top.Draw (); - Assert.True (tv.ProcessKey (new KeyEvent (tv.Autocomplete.CloseKey, new KeyModifiers ()))); + Assert.True (tv.OnKeyPressed (new KeyEventArgs (tv.Autocomplete.CloseKey, new KeyModifiers ()))); Assert.Equal ($"F Fortunately super feature.", tv.Text); Assert.Equal (new Point (1, 0), tv.CursorPosition); Assert.Empty (tv.Autocomplete.Suggestions); Assert.Equal (3, g.AllSuggestions.Count); Assert.False (tv.Autocomplete.Visible); tv.PositionCursor (); - Assert.True (tv.ProcessKey (new KeyEvent (tv.Autocomplete.Reopen, new KeyModifiers ()))); + Assert.True (tv.OnKeyPressed (new KeyEventArgs (tv.Autocomplete.Reopen, new KeyModifiers ()))); Assert.Equal ($"F Fortunately super feature.", tv.Text); Assert.Equal (new Point (1, 0), tv.CursorPosition); Assert.Equal (2, tv.Autocomplete.Suggestions.Count); Assert.Equal (3, g.AllSuggestions.Count); - Assert.True (tv.ProcessKey (new KeyEvent (tv.Autocomplete.SelectionKey, new KeyModifiers ()))); + Assert.True (tv.OnKeyPressed (new KeyEventArgs (tv.Autocomplete.SelectionKey, new KeyModifiers ()))); tv.PositionCursor (); Assert.Equal ($"Fortunately Fortunately super feature.", tv.Text); Assert.Equal (new Point (11, 0), tv.CursorPosition); @@ -178,7 +178,7 @@ public void CursorLeft_CursorRight_Mouse_Button_Pressed_Does_Not_Show_Popup () Application.Begin (top); for (int i = 0; i < 7; i++) { - Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ()))); + Assert.True (tv.OnKeyPressed (new KeyEventArgs (Key.CursorRight, new KeyModifiers ()))); Application.Refresh (); if (i < 4 || i > 5) { TestHelpers.AssertDriverContentsWithFrameAre (@" @@ -202,51 +202,51 @@ This a long line and against TextView. and against ", output); - Assert.True (tv.ProcessKey (new KeyEvent (Key.g, new KeyModifiers ()))); + Assert.True (tv.OnKeyPressed (new KeyEventArgs (Key.g, new KeyModifiers ()))); Application.Refresh (); TestHelpers.AssertDriverContentsWithFrameAre (@" This ag long line and against TextView. against ", output); - Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ()))); + Assert.True (tv.OnKeyPressed (new KeyEventArgs (Key.CursorLeft, new KeyModifiers ()))); Application.Refresh (); TestHelpers.AssertDriverContentsWithFrameAre (@" This ag long line and against TextView. against ", output); - Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ()))); + Assert.True (tv.OnKeyPressed (new KeyEventArgs (Key.CursorLeft, new KeyModifiers ()))); Application.Refresh (); TestHelpers.AssertDriverContentsWithFrameAre (@" This ag long line and against TextView. against ", output); - Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ()))); + Assert.True (tv.OnKeyPressed (new KeyEventArgs (Key.CursorLeft, new KeyModifiers ()))); Application.Refresh (); TestHelpers.AssertDriverContentsWithFrameAre (@" This ag long line and against TextView.", output); for (int i = 0; i < 3; i++) { - Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ()))); + Assert.True (tv.OnKeyPressed (new KeyEventArgs (Key.CursorRight, new KeyModifiers ()))); Application.Refresh (); TestHelpers.AssertDriverContentsWithFrameAre (@" This ag long line and against TextView. against ", output); } - Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace, new KeyModifiers ()))); + Assert.True (tv.OnKeyPressed (new KeyEventArgs (Key.Backspace, new KeyModifiers ()))); Application.Refresh (); TestHelpers.AssertDriverContentsWithFrameAre (@" This a long line and against TextView. and against ", output); - Assert.True (tv.ProcessKey (new KeyEvent (Key.n, new KeyModifiers ()))); + Assert.True (tv.OnKeyPressed (new KeyEventArgs (Key.n, new KeyModifiers ()))); Application.Refresh (); TestHelpers.AssertDriverContentsWithFrameAre (@" This an long line and against TextView. and ", output); - Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ()))); + Assert.True (tv.OnKeyPressed (new KeyEventArgs (Key.CursorRight, new KeyModifiers ()))); Application.Refresh (); TestHelpers.AssertDriverContentsWithFrameAre (@" This an long line and against TextView.", output); diff --git a/UnitTests/Text/CollectionNavigatorTests.cs b/UnitTests/Text/CollectionNavigatorTests.cs index 9031b157a9..70067fec9a 100644 --- a/UnitTests/Text/CollectionNavigatorTests.cs +++ b/UnitTests/Text/CollectionNavigatorTests.cs @@ -382,7 +382,7 @@ public void IsCompatibleKey_Does_Not_Allow_Alt_And_Ctrl_Keys () { // test all Keys foreach (Key key in Enum.GetValues (typeof (Key))) { - var ke = new KeyEvent (key, new KeyModifiers () { + var ke = new KeyEventArgs (key, new KeyModifiers () { Alt = key == Key.AltMask, Ctrl = key == Key.CtrlMask, Shift = key == Key.ShiftMask @@ -395,7 +395,7 @@ public void IsCompatibleKey_Does_Not_Allow_Alt_And_Ctrl_Keys () } // test Capslock, Numlock and Scrolllock - Assert.True (CollectionNavigator.IsCompatibleKey (new KeyEvent (Key.Null, new KeyModifiers () { + Assert.True (CollectionNavigator.IsCompatibleKey (new KeyEventArgs (Key.Null, new KeyModifiers () { Alt = false, Ctrl = false, Shift = false, diff --git a/UnitTests/UICatalog/ScenarioTests.cs b/UnitTests/UICatalog/ScenarioTests.cs index 19327ece95..c53742098e 100644 --- a/UnitTests/UICatalog/ScenarioTests.cs +++ b/UnitTests/UICatalog/ScenarioTests.cs @@ -69,12 +69,12 @@ public void Run_All_Scenarios () FakeConsole.PushMockKeyPress (Application.QuitKey); // The only key we care about is the QuitKey - Application.Top.KeyPressed += (object sender, KeyEventEventArgs args) => { - output.WriteLine ($" Keypress: {args.KeyEvent.Key}"); + Application.Top.KeyPressed += (object sender, KeyEventArgs args) => { + output.WriteLine ($" Keypress: {args.Key}"); // BUGBUG: (#2474) For some reason ReadKey is not returning the QuitKey for some Scenarios // by adding this Space it seems to work. // See #2474 for why this is commented out - Assert.Equal (Application.QuitKey, args.KeyEvent.Key); + Assert.Equal (Application.QuitKey, args.Key); }; uint abortTime = 500; @@ -156,9 +156,9 @@ public void Run_Generic () }; var token = Application.AddTimeout (TimeSpan.FromMilliseconds (ms), abortCallback); - Application.Top.KeyPressed += (object sender, KeyEventEventArgs args) => { + Application.Top.KeyPressed += (object sender, KeyEventArgs args) => { // See #2474 for why this is commented out - Assert.Equal (Key.CtrlMask | Key.Q, args.KeyEvent.Key); + Assert.Equal (Key.CtrlMask | Key.Q, args.Key); }; generic.Init (); diff --git a/UnitTests/View/KeyboardTests.cs b/UnitTests/View/KeyboardTests.cs index a9557294b7..d273726a88 100644 --- a/UnitTests/View/KeyboardTests.cs +++ b/UnitTests/View/KeyboardTests.cs @@ -28,7 +28,7 @@ public void KeyPress_Handled_To_True_Prevents_Changes () text.KeyPressed += (s, e) => { e.Handled = true; Assert.True (e.Handled); - Assert.Equal (Key.N, e.KeyEvent.Key); + Assert.Equal (Key.N, e.Key); }; top.Add (text); @@ -55,21 +55,21 @@ public void KeyDown_And_KeyUp_Events_Must_Called_Before_OnKeyDown_And_OnKeyUp () var view = new DerivedView (); view.KeyDown += (s, e) => { - Assert.Equal (Key.a, e.KeyEvent.Key); + Assert.Equal (Key.a, e.Key); Assert.False (keyDown); Assert.False (view.IsKeyDown); e.Handled = true; keyDown = true; }; view.KeyPressed += (s, e) => { - Assert.Equal (Key.a, e.KeyEvent.Key); + Assert.Equal (Key.a, e.Key); Assert.False (keyPress); Assert.False (view.IsKeyPress); e.Handled = true; keyPress = true; }; view.KeyUp += (s, e) => { - Assert.Equal (Key.a, e.KeyEvent.Key); + Assert.Equal (Key.a, e.Key); Assert.False (keyUp); Assert.False (view.IsKeyUp); e.Handled = true; @@ -106,19 +106,19 @@ public DerivedView () public bool IsKeyUp { get; set; } public override string Text { get; set; } - public override bool OnKeyDown (KeyEvent keyEvent) + public override bool OnKeyDown (KeyEventArgs keyEvent) { IsKeyDown = true; return true; } - public override bool ProcessKey (KeyEvent keyEvent) + public override bool OnKeyPressed (KeyEventArgs args) { IsKeyPress = true; return true; } - public override bool OnKeyUp (KeyEvent keyEvent) + public override bool OnKeyUp (KeyEventArgs keyEvent) { IsKeyUp = true; return true; @@ -137,10 +137,10 @@ public void KeyDown_And_KeyUp_Events_With_Only_Key_Modifiers (bool shift, bool a var view = new DerivedView (); view.KeyDown += (s, e) => { - Assert.Equal (-1, e.KeyEvent.KeyValue); - Assert.Equal (shift, e.KeyEvent.IsShift); - Assert.Equal (alt, e.KeyEvent.IsAlt); - Assert.Equal (control, e.KeyEvent.IsCtrl); + Assert.Equal (-1, e.KeyValue); + Assert.Equal (shift, e.IsShift); + Assert.Equal (alt, e.IsAlt); + Assert.Equal (control, e.IsCtrl); Assert.False (keyDown); Assert.False (view.IsKeyDown); keyDown = true; @@ -149,10 +149,10 @@ public void KeyDown_And_KeyUp_Events_With_Only_Key_Modifiers (bool shift, bool a keyPress = true; }; view.KeyUp += (s, e) => { - Assert.Equal (-1, e.KeyEvent.KeyValue); - Assert.Equal (shift, e.KeyEvent.IsShift); - Assert.Equal (alt, e.KeyEvent.IsAlt); - Assert.Equal (control, e.KeyEvent.IsCtrl); + Assert.Equal (-1, e.KeyValue); + Assert.Equal (shift, e.IsShift); + Assert.Equal (alt, e.IsAlt); + Assert.Equal (control, e.IsCtrl); Assert.False (keyUp); Assert.False (view.IsKeyUp); keyUp = true; diff --git a/UnitTests/View/Layout/DimTests.cs b/UnitTests/View/Layout/DimTests.cs index c70b66d458..94219071f4 100644 --- a/UnitTests/View/Layout/DimTests.cs +++ b/UnitTests/View/Layout/DimTests.cs @@ -688,7 +688,7 @@ public void Dim_Add_Operator () var count = 0; field.KeyDown += (s, k) => { - if (k.KeyEvent.Key == Key.Enter) { + if (k.Key == Key.Enter) { field.Text = $"Label {count}"; var label = new Label (field.Text) { X = 0, Y = view.Bounds.Height, Width = 20 }; view.Add (label); @@ -703,7 +703,7 @@ public void Dim_Add_Operator () }; Application.Iteration += (s, a) => { - while (count < 20) field.OnKeyDown (new KeyEvent (Key.Enter, new KeyModifiers ())); + while (count < 20) field.OnKeyDown (new KeyEventArgs (Key.Enter, new KeyModifiers ())); Application.RequestStop (); }; @@ -1050,7 +1050,7 @@ public void Dim_Add_Operator_With_Text () var listLabels = new List