Ejemplo n.º 1
0
        /// <summary>
        /// Invokes <see cref="KeyPress"/>
        /// </summary>
        /// <param name="keyboard">The keyboard object which received the event</param>
        /// <param name="args">The key that was pressed</param>
        public virtual void OnKeyPressed(object keyboard, ConsoleKeyEventArgs args)
        {
            args.Handled = HandleKeyPress(keyboard, args);

            // handle priority key presses
            if (PriorityKeyPress != null)
            {
                foreach (EventHandler <ConsoleKeyEventArgs> handler in PriorityKeyPress.GetInvocationList())
                {
                    handler(keyboard, args);

                    if (args.Handled)
                    {
                        break;
                    }
                }
            }

            // handle normal key presses
            if (KeyPress != null && !args.Handled)
            {
                foreach (EventHandler <ConsoleKeyEventArgs> handler in KeyPress.GetInvocationList())
                {
                    handler(keyboard, args);

                    if (args.Handled)
                    {
                        break;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        protected override bool HandleKeyPress(object sender, ConsoleKeyEventArgs args)
        {
            bool handled = false;

            if (HasFocus && args.Key.Key == ConsoleKey.Enter)
            {
                double current_millis = (DateTime.UtcNow - UNIX_EPOCH).TotalMilliseconds;

                if (current_millis - LAST_ACTIVATION > ACTIVATION_DELAY)
                {
                    if (Action != null)
                    {
                        Action(sender, new ComponentEventArgs(this));
                    }
                    else
                    {
                        DebugLog.LogComponent("Warning: button with text '" + Text + "' has no action");
                    }

                    LAST_ACTIVATION = current_millis;

                    handled = true;
                }
            }

            return(handled);
        }
Ejemplo n.º 3
0
        public void KeyEvent_SwitchBuffersKey_BuffersSwitched()
        {
            bool active = true;

            using var consoleController = new StubbedConsoleController
                  {
                      ActiveScreenGet        = () => active,
                      ActiveScreenSetBoolean = b => active = b
                  };
            using var api = new StubbedNativeCalls();
            var graphicsProvider = new StubbedGraphicsProvider();

            using var sut = new ConControls.Controls.ConsoleWindow(api, consoleController, graphicsProvider)
                  {
                      SwitchConsoleBuffersKey = ConControls.Controls.KeyCombination.F11
                  };

            var e = new ConsoleKeyEventArgs(new KEY_EVENT_RECORD
            {
                KeyDown        = 1,
                VirtualKeyCode = VirtualKey.F11
            });

            consoleController.KeyEventEvent(consoleController, e);
            active.Should().BeFalse();
            consoleController.KeyEventEvent(consoleController, e);
            active.Should().BeTrue();
            consoleController.KeyEventEvent(consoleController, e);
            active.Should().BeFalse();
        }
Ejemplo n.º 4
0
        private static async void KeyHandler_KeyEvent(object sender, ConsoleKeyEventArgs e)
        {
            switch (e.KeyInfo.Key)
            {
            case ConsoleKey.P:
                var status = await _musicCastClient.GetStatusAsync();

                Console.WriteLine($"Status is {status}");
                switch (status.power)
                {
                case "on":
                    await _musicCastClient.SetPowerAsync(false);

                    break;

                default:
                    await _musicCastClient.SetPowerAsync(true);

                    break;
                }
                status = await _musicCastClient.GetStatusAsync();

                Console.WriteLine($"Status is now {status.power}");
                break;
            }
        }
Ejemplo n.º 5
0
 internal KeyEventArgs(ConsoleKeyEventArgs e)
 {
     UnicodeChar     = e.UnicodeChar;
     RepeatCount     = e.RepeatCount;
     VirtualKey      = e.VirtualKeyCode;
     VirtualScanCode = e.VirtualScanCode;
     KeyDown         = e.KeyDown;
     ControlKeys     = e.ControlKeys;
 }
Ejemplo n.º 6
0
        protected override bool HandleKeyPress(object sender, ConsoleKeyEventArgs args)
        {
            // if this component doesn't have focus, don't do the keypress
            if (!HasFocus)
            {
                return(false);
            }

            bool handled = false;

            string text_pre = Text;

            List <Tuple <int, int> > modified = new List <Tuple <int, int> >();

            modified.Add(new Tuple <int, int>(Left + selectedIndex, Top));

            switch (args.Key.Key)
            {
            case ConsoleKey.Backspace:
                handled = Delete();
                break;

            case ConsoleKey.LeftArrow:
                if (selectedIndex > 0)
                {
                    selectedIndex--;
                    handled = true;
                }
                break;

            case ConsoleKey.RightArrow:
                if (selectedIndex < Text.Length)
                {
                    selectedIndex++;
                    handled = true;
                }
                break;
            }

            if (!char.IsControl(args.Key.KeyChar))
            {
                handled = Insert(args.Key.KeyChar);
            }

            modified.Add(new Tuple <int, int>(Left + selectedIndex, Top));

            OnRequestRedraw(this, new RedrawEventArgs(Rectangle.Encompassing(modified)));

            // if the text has changed, it needs to be redrawn.
            if (!Text.Equals(text_pre))
            {
                handled = true;
            }

            return(handled);
        }
Ejemplo n.º 7
0
        static ConsoleKeyEventArgs MakeKeyEvent(char keyChar, ConsoleKey key, int scanCode, bool keyDown)
        {
            ConsoleKeyEventArgs eKey = new ConsoleKeyEventArgs();

            eKey.KeyDown         = keyDown;
            eKey.RepeatCount     = 1;
            eKey.KeyChar         = keyChar;
            eKey.Key             = key;
            eKey.VirtualScanCode = scanCode;
            return(eKey);
        }
        public void ConsoleKeyEventArgs_ConstructorSetsCorrectValues()
        {
            KEY_EVENT_RECORD record = new KEY_EVENT_RECORD
            {
                KeyDown         = 12,
                RepeatCount     = 123,
                VirtualKeyCode  = VirtualKey.Accept,
                UnicodeChar     = 'x',
                VirtualScanCode = 321,
                ControlKeys     = ControlKeyStates.RIGHT_ALT_PRESSED
            };
            var sut = new ConsoleKeyEventArgs(record);

            sut.KeyDown.Should().BeTrue();
            sut.ControlKeys.Should().Be(record.ControlKeys);
            sut.RepeatCount.Should().Be(123);
            sut.VirtualKeyCode.Should().Be(record.VirtualKeyCode);
            sut.UnicodeChar.Should().Be('x');
            sut.VirtualScanCode.Should().Be(record.VirtualScanCode);
        }
Ejemplo n.º 9
0
        private void HandleKeypress(object sender, ConsoleKeyEventArgs args)
        {
            if (!Parent.Visible || !active)
            {
                return;
            }

            ConsoleKey Dec = Horizontal ? HORZ_DEC : VERT_DEC;
            ConsoleKey Inc = Horizontal ? HORZ_INC : VERT_INC;

            if (args.Key.Key == Dec)
            {
                SetSelectedIndex(Mod(selectedIndex - 1, Components.Count));
                args.Handled = true;
            }
            else if (args.Key.Key == Inc)
            {
                SetSelectedIndex(Mod(selectedIndex + 1, Components.Count));
                args.Handled = true;
            }
        }
Ejemplo n.º 10
0
        internal static bool Matches(this ConsoleKeyEventArgs e, KeyCombination?combination)
        {
            if (combination == null)
            {
                return(false);
            }
            var combi = new KeyCombination(e.VirtualKeyCode);

            if (e.ControlKeys.HasFlag(ControlKeyStates.LEFT_ALT_PRESSED) || e.ControlKeys.HasFlag(ControlKeyStates.RIGHT_ALT_PRESSED))
            {
                combi = combi.WithAlt();
            }
            if (e.ControlKeys.HasFlag(ControlKeyStates.LEFT_CTRL_PRESSED) || e.ControlKeys.HasFlag(ControlKeyStates.RIGHT_CTRL_PRESSED))
            {
                combi = combi.WithCtrl();
            }
            if (e.ControlKeys.HasFlag(ControlKeyStates.SHIFT_PRESSED))
            {
                combi = combi.WithShift();
            }
            return(combi == combination.Value);
        }
Ejemplo n.º 11
0
        private static void KeyHandler_KeyEvent(object sender, ConsoleKeyEventArgs e)
        {
            switch (e.KeyInfo.Key)
            {
            case ConsoleKey.M:
                _multicastServer.SsdpDiscover();
                break;

            case ConsoleKey.J:
                Console.WriteLine("JoinGroup");
                _multicastServer.JoinGroup();
                break;

            case ConsoleKey.C:
                Console.WriteLine("SendConnectUdp");
                _multicastService.SendConnectUdp();
                break;

            case ConsoleKey.V:
                Console.WriteLine("SendNotSureWhatThisDoesUdp");
                _multicastService.SendNotSureWhatThisDoesUdp();
                break;
            }
        }
Ejemplo n.º 12
0
        public void KeyEvent_ShiftTab_FocusChanged()
        {
            using var consoleController = new StubbedConsoleController();
            using var api = new StubbedNativeCalls();
            var graphicsProvider = new StubbedGraphicsProvider();

            using var sut = new ConControls.Controls.ConsoleWindow(api, consoleController, graphicsProvider);

            var t1 = new ConControls.Controls.TextBlock(sut)
            {
                Parent = sut
            };
            var t2 = new ConControls.Controls.TextBlock(sut)
            {
                Parent = sut
            };
            var eventArgs = new ConsoleKeyEventArgs(new KEY_EVENT_RECORD
            {
                ControlKeys    = ControlKeyStates.SCROLLLOCK_ON | ControlKeyStates.SHIFT_PRESSED,
                KeyDown        = 1,
                VirtualKeyCode = VirtualKey.Tab
            });

            consoleController.KeyEventEvent(consoleController,
                                            eventArgs);
            sut.FocusedControl.Should().Be(t2);
            consoleController.KeyEventEvent(consoleController,
                                            eventArgs);
            sut.FocusedControl.Should().Be(t1);
            consoleController.KeyEventEvent(consoleController,
                                            eventArgs);
            sut.FocusedControl.Should().Be(t2);
            consoleController.KeyEventEvent(consoleController,
                                            eventArgs);
            sut.FocusedControl.Should().Be(t1);
        }
Ejemplo n.º 13
0
 static void ib_KeyUp(object sender, ConsoleKeyEventArgs e)
 {
     sb.WriteLine(String.Format("KeyUp: {0}, {1}", e.Key, e.VirtualScanCode));
 }
Ejemplo n.º 14
0
 private void keyHandler_KeyEvent(object sender, ConsoleKeyEventArgs e)
 {
     HandleKey(e.KeyInfo);
 }
Ejemplo n.º 15
0
 private void keyHandler_KeyEvent(object sender, ConsoleKeyEventArgs e)
 {
     HandleKey(e.KeyInfo);
 }
Ejemplo n.º 16
0
 static void ib_KeyDown(object sender, ConsoleKeyEventArgs e)
 {
     sb.WriteLine(string.Format("Key Down, {0}, {1}", e.Key, Convert.ToInt32(e.KeyChar)));
 }
Ejemplo n.º 17
0
 static void ib_KeyUp(object sender, ConsoleKeyEventArgs e)
 {
     sb.WriteLine(string.Format("Key Up, {0}", e.Key));
 }
Ejemplo n.º 18
0
 /// <summary>
 /// Handles the keypress for this component.
 /// </summary>
 /// <param name="keyboard">The keyboard that sent the event.</param>
 /// <param name="args">The key.</param>
 /// <returns><code>true</code> if the keypress was handled, false otherwise.</returns>
 protected virtual bool HandleKeyPress(object keyboard, ConsoleKeyEventArgs args)
 {
     return(false);
 }
Ejemplo n.º 19
0
 static void ib_KeyDown(object sender, ConsoleKeyEventArgs e)
 {
     sb.WriteLine(String.Format("KeyDown: '{0}' {1}", e.KeyChar, e.Key));
 }