Exemple #1
0
        public bool HandleInput(CommandKeys key)
        {
            if (FocusedWidget == null)
                return false;

            return FocusedWidget.HandleInput(key);
        }
Exemple #2
0
        public bool HandleInput(CommandKeys key)
        {
            WasHandleInputCalled = true;
            HandleInputArgument = key;

            return true;
        }
        public bool HandleInput(CommandKeys key)
        {
            switch (key)
            {
                case CommandKeys.Down:
                    spriteState.MoveDirection(Direction.Down);
                    break;
                case CommandKeys.Left:
                    spriteState.MoveDirection(Direction.Left);
                    break;
                case CommandKeys.Right:
                    spriteState.MoveDirection(Direction.Right);
                    break;
                case CommandKeys.Up:
                    spriteState.MoveDirection(Direction.Up);
                    break;
                case CommandKeys.Select:
                    break;
                case CommandKeys.Back:
                    engineInterface.Exit();
                    break;
                default:
                    throw new ArgumentOutOfRangeException("key", key, null);
            }

            return true;
        }
Exemple #4
0
        public void HandleInput_OtherKeysThanSelect_DoesNotHandle(CommandKeys key)
        {
            var messageBox = CreateMessageBox();

            Assert.False(messageBox.HandleInput(key));
        }
Exemple #5
0
 public abstract bool HandleInput(CommandKeys key);
Exemple #6
0
 public void AddKeyCommand(KeyCommandEnum key, string command)
 {
     CommandKeys.AddKeyCommand(key, command, true);
 }
Exemple #7
0
 public void ClearKeyCommand(KeyCommandEnum key)
 {
     CommandKeys.ClearKeyCommand(key);
 }
Exemple #8
0
 public void AddKeyCommand(KeyCommandEnum key, string command, bool autoSend)
 {
     CommandKeys.AddKeyCommand(key, command, autoSend);
 }
        public bool AddKey(System.Windows.Input.Key key, CommandKeys command)
        {
            string keyStr = string.Format("{0}-{1}", this.KeyModifiers.ToString(), key.ToString());
            int alts = HotKey.GlobalAddAtom(keyStr);

            if (key != Key.None)
            {
                try
                {
                    System.Windows.Forms.Keys keyF = (System.Windows.Forms.Keys)Enum.Parse(typeof(System.Windows.Forms.Keys), key.ToString());
                    if (!HotKey.RegisterHotKey(this.Handle, alts, this.KeyModifiers, (int)keyF))
                    {
                        HotKey.GlobalDeleteAtom((short)alts);
                        string msg = string.Empty;
                        int errorCode = Marshal.GetLastWin32Error();
                        switch (errorCode)
                        {
                            case 1409:
                                msg = "热键[" + keyF .ToString()+ "]已经注册!";
                                break;
                            default:
                                msg = errorCode.ToString();
                                break;
                        }
                        //DialogManager.ShowMessageAsync(Application.Current.MainWindow as MetroWindow, "喜马拉雅", msg);
                        return false;
                    }
                }
                catch
                {
                    return false;
                }
            }
            if (!this.Keys.ContainsKey(key))
            {
                this.Keys.Add(key, command);
            }
            return true;
        }
Exemple #10
0
        void KeypressAsync_method()
        {
            ICommandResponse result        = null;
            string           resultUrl     = null;
            Func <Task>      subjectAction = null;
            IRokuResponse    rokuResponse  = null;

            describe["when the request succeeds"] = () =>
            {
                it["should indicate a success"] = () =>
                {
                    result.IsSuccess.Should().BeTrue();
                };

                before = () =>
                {
                    rokuResponse  = TestHelper.BuildRokuResponse();
                    subjectAction = async() => result = await subject.KeypressAsync('z');
                };

                describe["when a command key is sent"] = () =>
                {
                    CommandKeys commandKey = CommandKeys.Home;

                    it["should convert the key sent to it's querystring equivelant"] = () =>
                    {
                        resultUrl.Should().Contain(commandKey.ToRouteValue());
                    };

                    before = () =>
                             subjectAction = async() => result = await subject.KeypressAsync(commandKey);
                };

                describe["when a character key is sent"] = () =>
                {
                    char charKey = '"';

                    it["should convert the key sent to it's querystring equivelant"] = () =>
                    {
                        resultUrl.Should().Contain(charKey.ToRouteValue());
                    };

                    before = () =>
                             subjectAction = async() => result = await subject.KeypressAsync(charKey);
                };
            };

            describe["when the request fails"] = () =>
            {
                it["should indicatate a failure"] = () =>
                {
                    result.IsSuccess.Should().BeFalse();
                };

                before = () =>
                {
                    rokuResponse  = TestHelper.BuildRokuResponse(statusCode: HttpStatusCode.ServiceUnavailable);
                    subjectAction = async() => result = await subject.KeypressAsync('z');
                };
            };

            before = () =>
            {
                InitializeMocks();
                rokuRequest.Setup(m => m.GetResponseAsync(UrlUtils.KeyPressUrlFor(rokuUri, It.IsAny <string>()), "POST"))
                .ReturnsAsync((string url, string keyString) =>
                {
                    resultUrl = url;
                    return(rokuResponse);
                });
            };

            actAsync = async() =>
            {
                InitializeSubject();
                await subjectAction();
            };
        }
Exemple #11
0
        void KeyDownAsync_method()
        {
            ICommandResponse result        = null;
            Func <Task>      commandAction = null;
            IRokuResponse    rokuResponse  = null;

            describe["when the request succeeds"] = () =>
            {
                string expectedLastKeyPressed = null;

                it["should indicate a success"] = () =>
                {
                    result.IsSuccess.Should().BeTrue();
                };

                it["should keep the last key sent"] = () =>
                {
                    subject._lastKeyPressed.Should().NotBeNull();
                };

                before = () => rokuResponse = TestHelper.BuildRokuResponse();

                describe["when a command key is sent"] = () =>
                {
                    CommandKeys commandKey = CommandKeys.Home;

                    it["should convert the key sent to it's querystring equivelant"] = () =>
                    {
                        subject._lastKeyPressed.Should().Be(expectedLastKeyPressed);
                    };

                    before = () =>
                    {
                        expectedLastKeyPressed = commandKey.ToRouteValue();
                        commandAction          = async() => result = await subject.KeyDownAsync(commandKey);
                    };
                };

                describe["when a character key is sent"] = () =>
                {
                    char charKey = ' ';

                    it["should convert the key sent to it's querystring equivelant"] = () =>
                    {
                        subject._lastKeyPressed.Should().Be(charKey.ToRouteValue());
                    };

                    before = () =>
                             commandAction = async() => result = await subject.KeyDownAsync(charKey);
                };
            };

            describe["when the request fails"] = () =>
            {
                it["should indicate a failure"] = () =>
                {
                    result.IsSuccess.Should().BeFalse();
                };

                before = () => rokuResponse = TestHelper.BuildRokuResponse(statusCode: HttpStatusCode.Forbidden);
            };

            before = () =>
            {
                commandAction = async() => result = await subject.KeyDownAsync('A');

                InitializeMocks();
                rokuRequest.Setup(m => m.GetResponseAsync(UrlUtils.KeyDownUrlFor(rokuUri, It.IsAny <string>()), "POST"))
                .ReturnsAsync(() => rokuResponse);
            };

            actAsync = async() =>
            {
                InitializeSubject();
                await commandAction();
            };
        }
Exemple #12
0
        public void HandleInput_WithVisibleRowsColumnsSet_StartIndexAdjusts(int rows, int columns, int visibleRows, int visibleColumns,
            int selectedRow, int selectedColumn,
            CommandKeys key,
            int startRow, int startColumn)
        {
            var tableViewMock = new TableViewMock();
            var table = CreateTableWidget(tableViewMock, rows, columns, visibleRows, visibleColumns);
            var startIndex = new TableIndex(startRow, startColumn);

            table.SelectCell(selectedRow, selectedColumn);
            table.HandleInput(key);

            AssertIndex(startIndex, tableViewMock.StartIndex.Value);

        }
Exemple #13
0
        public void HandleInput_StartingFromSomeCell_TableViewSelectCellIsCalled(int rows, int columns, int selectedRow, int selectedColumn, 
                                          CommandKeys key, int newRow, int newColumns)
        {
            var tableViewMock = new Mock<TableViewMock> { CallBase = true };
            var table = CreateTableWidget(tableViewMock.Object, rows, columns);
            table.SelectCell(selectedRow, selectedColumn);

            tableViewMock.ResetCalls();
            tableViewMock.Setup(o => o.SetCellSelection(newRow, newColumns, true)).Verifiable();

            table.HandleInput(key);

            tableViewMock.Verify();
        }
Exemple #14
0
        public void HandleInput_TableViewSelectionFails_CursorNotChanged(int rows, int columns, int initialSelectedRow, int initialSelectedColumn,
            CommandKeys key)
        {
            var tableViewMock = new TableViewMock();
            var table = CreateTableWidget(tableViewMock, rows, columns);

            table.SelectCell(initialSelectedRow, initialSelectedColumn);
            tableViewMock.SelectionReturnValue = false;

            table.HandleInput(key);

            Assert.AreEqual(initialSelectedRow, table.cursorRow);
            Assert.AreEqual(initialSelectedColumn, table.cursorColumn);
        }