コード例 #1
0
        protected override bool OnKeyDown(TvConsoleKeyboardEvent evt, BehaviorContext <WindowState> updateContext)
        {
            var keyInfo = evt.AsConsoleKeyInfo();

            if (keyInfo.Modifiers == ConsoleModifiers.Control && keyInfo.Key == ConsoleKey.Spacebar)
            {
                _moving = true;
                return(false);
            }

            if (_moving)
            {
                switch (keyInfo.Key)
                {
                case ConsoleKey.RightArrow:
                    updateContext.UpdateViewport(updateContext.Viewport.Translate(new TvPoint(1, 0)));
                    return(true);

                case ConsoleKey.LeftArrow:
                    updateContext.UpdateViewport(updateContext.Viewport.Translate(new TvPoint(-1, 0)));
                    return(true);

                case ConsoleKey.UpArrow:
                    updateContext.UpdateViewport(updateContext.Viewport.Translate(new TvPoint(0, -1)));
                    return(true);

                case ConsoleKey.DownArrow:
                    updateContext.UpdateViewport(updateContext.Viewport.Translate(new TvPoint(0, 1)));
                    return(true);

                case ConsoleKey.Escape:
                    _moving = false;
                    return(false);
                }
            }
            else
            {
                if (keyInfo.Key == ConsoleKey.Escape)
                {
                    updateContext.State.RequestClose();
                }
            }
            return(false);
        }