Exemple #1
0
        public void Move(object sender, Avalonia.Input.KeyEventArgs pressed)
        {
            switch (pressed.Key)
            {
            case Avalonia.Input.Key.W:
            {
                MoveCharacter(pressed, 0, -72);
                break;
            }

            case Avalonia.Input.Key.S:
            {
                MoveCharacter(pressed, 0, 72);
                break;
            }

            case Avalonia.Input.Key.A:
            {
                MoveCharacter(pressed, -72, -0);
                break;
            }

            case Avalonia.Input.Key.D:
            {
                MoveCharacter(pressed, 72, 0);
                break;
            }

            default:
                break;
            }
            DrawChar.SetPosition(Image, PositionOnArray.X, PositionOnArray.Y);
        }
Exemple #2
0
        public override void DrawCharacter(Point newPoint, Avalonia.Input.KeyEventArgs pressed)
        {
            switch (pressed.Key)
            {
            case Avalonia.Input.Key.W:
            {
                ImagePath = @"C:\Users\bajer\Documents\wanderer-cs\img\hero-up.png";
                break;
            }

            case Avalonia.Input.Key.S:
            {
                ImagePath = @"C:\Users\bajer\Documents\wanderer-cs\img\hero-down.png";
                break;
            }

            case Avalonia.Input.Key.A:
            {
                ImagePath = @"C:\Users\bajer\Documents\wanderer-cs\img\mario-left.png";
                break;
            }

            case Avalonia.Input.Key.D:
            {
                ImagePath = @"C:\Users\bajer\Documents\wanderer-cs\img\hero-right.png";
                break;
            }

            default:
                break;
            }
            Image.Source = new Bitmap(ImagePath);
        }
        private void MainWindow_KeyUp(object sender, Avalonia.Input.KeyEventArgs e)
        {
            switch (e.Key)
            {
            case Key.D:
                MoveRight(playerTile);

                break;

            case Key.A:
                MoveLeft(playerTile);

                break;

            case Key.W:
                MoveUp(playerTile);

                break;

            case Key.S:
                MoveDown(playerTile);

                break;
            }
        }
 private void TextBoxKeyDown(object?sender, Avalonia.Input.KeyEventArgs e)
 {
     if (e.Key == Key.Return)
     {
         ReturnAssetToAdd();
     }
 }
 private void BoxPathId_KeyDown(object?sender, Avalonia.Input.KeyEventArgs e)
 {
     if (e.Key == Key.Return)
     {
         ReturnAssetToGoTo();
     }
 }
Exemple #6
0
 private void AboutWindow_KeyDown(object sender, Avalonia.Input.KeyEventArgs e)
 {
     if (e.Key == Key.Escape)
     {
         Close();
     }
     else
     {
         if (lastKeys.Count == 10)
         {
             lastKeys.Dequeue();
         }
         lastKeys.Enqueue(e.Key);
         if (lastKeys.Count == 10 && lastKeys.SequenceEqual(konamiCodeKeys))
         {
             if (((Grid)Content).Children[0] is Image == false && Application.Current.TryFindResource("dreamcastLogoDrawingImage", out object img))
             {
                 ((Grid)Content).Children.Insert(0, new Image {
                     Source = (DrawingImage)img
                 });
             }
             Title = "Dreamcast Lives!";
             lastKeys.Clear();
         }
     }
 }
Exemple #7
0
        protected override void OnKeyDown(KeyEventArgs e)
        {
            string text = this.Text;

            switch (e.Key)
            {
                case Key.Left:
                    --this.CaretIndex;
                    break;
                
                case Key.Right:
                    ++this.CaretIndex;
                    break;

                case Key.Back:
                    if (this.caretIndex > 0)
                    {                        
                        this.Text = text.Substring(0, this.caretIndex - 1) + text.Substring(this.caretIndex);
                        --this.CaretIndex;
                    }

                    break;

                case Key.Delete:
                    if (this.caretIndex < text.Length)
                    {
                        this.Text = text.Substring(0, this.caretIndex) + text.Substring(this.caretIndex + 1);
                    }

                    break;
            }
        }
Exemple #8
0
 private void BoxName_KeyDown(object? sender, Avalonia.Input.KeyEventArgs e)
 {
     if (e.Key == Key.Return)
     {
         ReturnAssetToSearch();
     }
 }
        private static void WindowPreviewKeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.F12)
            {
                var window = (Window)sender;
                var devToolsWindow = default(Window);

                if (s_open.TryGetValue(window, out devToolsWindow))
                {
                    devToolsWindow.Activate();
                }
                else
                {
                    var devTools = new DevTools(window);

                    devToolsWindow = new Window
                    {
                        Width = 1024,
                        Height = 512,
                        Content = devTools,
                        DataTemplates = new DataTemplates
                        {
                            new ViewLocator<ReactiveObject>(),
                        }
                    };

                    devToolsWindow.Closed += devTools.DevToolsClosed;
                    s_open.Add((Window)sender, devToolsWindow);
                    devToolsWindow.Show();
                }
            }
        }
Exemple #10
0
        private void GotoTagBoxKeyDown(object sender, Avalonia.Input.KeyEventArgs e)
        {
            var box = (TextBox)sender;

            if (e.Key == Avalonia.Input.Key.Enter)
            {
                if (uint.TryParse(box.Text, out var id))
                {
                    var roots = DataCtx.LoadedScenario.TreeRoots;

                    foreach (var root in roots)
                    {
                        if (root.Id == id)
                        {
                            DataCtx.SelectedEntry = root;
                            break;
                        }
                        else
                        {
                            var found = TryFindChild(root, id, out var item);

                            if (found)
                            {
                                DataCtx.SelectedEntry = item;
                                break;
                            }
                        }
                    }
                }
            }

            bool TryFindChild(TagTreeEntryViewModel model, uint id, out TagTreeEntryViewModel result)
            {
                if (model.Children == null)
                {
                    result = null;
                    return(false);
                }

                foreach (var child in model.Children)
                {
                    if (child.Id == id)
                    {
                        result = child;
                        return(true);
                    }
                    else
                    {
                        if (TryFindChild(child, id, out result))
                        {
                            return(true);
                        }
                    }
                }

                result = null;
                return(false);
            }
        }
Exemple #11
0
        /// <summary>
        /// handles the txtAll key down
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void txtAll_KeyDown(object sender, Avalonia.Input.KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                try
                {
                    if (string.IsNullOrEmpty(((TextBox)sender).Text))
                    {
                        return;
                    }

                    string allTextResult = string.Empty;
                    CustomColor  = ColorPickerHelper.MakeColorFromHex(sender, CustomColor, out allTextResult);
                    _txtAll.Text = allTextResult;

                    Reposition();
                }
                catch
                {
                }
            }
            else if (e.Key == Key.Tab)
            {
                _txtAlpha.Focus();
            }

            string input = e.Key.ToString().Substring(1);

            if (string.IsNullOrEmpty(input))
            {
                input = e.Key.ToString();
            }
            if (input == "3" && _shift == true)
            {
                input = "#";
            }

            if (e.Key == Key.LeftShift || e.Key == Key.RightShift)
            {
                _shift = true;
            }
            else
            {
                _shift = false;
            }

            if (!(input == "#" || (input[0] >= 'A' && input[0] <= 'F') || (input[0] >= 'a' && input[0] <= 'F') || (input[0] >= '0' && input[0] <= '9')))
            {
                e.Handled = true;
            }
            if (input.Length > 1)
            {
                e.Handled = true;
            }
        }
Exemple #12
0
 private void OnRowKeyDown(object sender, Avalonia.Input.KeyEventArgs e)
 {
     if (sender is Control row && row.Parent == _grid)
     {
         if (e.Key == Key.Delete)
         {
             int rowIndex = Grid.GetRow(row);
             DeleteRow(rowIndex);
             Changed?.Invoke();
         }
     }
 }
        private void AvaloniaDynamicTextInputHandler_KeyRelease(object sender, Avalonia.Input.KeyEventArgs e)
        {
            var key = (HidKey)AvaloniaMappingHelper.ToInputKey(e.Key);

            if (!(KeyReleasedEvent?.Invoke(key)).GetValueOrDefault(true))
            {
                return;
            }

            e.RoutedEvent = _hiddenTextBox.GetKeyUpRoutedEvent();

            Dispatcher.UIThread.InvokeAsync(() =>
            {
                if (_canProcessInput)
                {
                    _hiddenTextBox.SendKeyUpEvent(e);
                }
            });
        }
        private void ZoomBorder_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.E)
            {
                zoomBorder.Extent();
            }

            if (e.Key == Key.F)
            {
                zoomBorder.Fill();
            }

            if (e.Key == Key.R)
            {
                zoomBorder.Reset();
            }

            if (e.Key == Key.T)
            {
                zoomBorder.ToggleAutoFitMode();
                zoomBorder.AutoFit();
            }
        }
Exemple #15
0
 /// <inheritdoc/>
 protected override void OnKeyDown(KeyEventArgs e)
 {
     // Ignore key presses.
 }
Exemple #16
0
 /// <summary>
 /// Called before the <see cref="KeyDown"/> event occurs.
 /// </summary>
 /// <param name="e">The event args.</param>
 protected virtual void OnKeyDown(KeyEventArgs e)
 {
 }
        public void OnKeyUp(KeyEventArgs e, int caretIndex, int line, int column)
        {
            if (e.Source == editor)
            {
                intellisenseJobRunner.InvokeAsync(() =>
                {
                    isProcessingKey = false;

                    if (intellisenseControl.IsVisible && caretIndex < intellisenseStartedAt)
                    {
                        CloseIntellisense();

                        SetCursor(caretIndex, line, column, EditorModel.UnsavedFiles.ToList(), false);
                    }
                });
            }
        }
        public void OnKeyDown(KeyEventArgs e, int caretIndex, int line, int column)
        {
            if (e.Source == editor)
            {
                capturedOnKeyDown = e.Key;

                if (intellisenseControl.IsVisible)
                {
                    switch (capturedOnKeyDown)
                    {
                        case Key.Down:
                            {
                                var index = intellisenseControl.CompletionData.IndexOf(intellisenseControl.SelectedCompletion);

                                if (index < intellisenseControl.CompletionData.Count - 1)
                                {
                                    intellisenseControl.SelectedCompletion = intellisenseControl.CompletionData[index + 1];
                                }

                                e.Handled = true;
                            }
                            break;

                        case Key.Up:
                            {
                                var index = intellisenseControl.CompletionData.IndexOf(intellisenseControl.SelectedCompletion);

                                if (index > 0)
                                {
                                    intellisenseControl.SelectedCompletion = intellisenseControl.CompletionData[index - 1];
                                }

                                e.Handled = true;
                            }
                            break;

                        case Key.Back:
                            if (caretIndex - 1 >= intellisenseStartedAt)
                            {
                                intellisenseJobRunner.InvokeAsync(() =>
                                {
                                    UpdateFilter(caretIndex - 1);
                                });
                            }
                            break;

                        case Key.Enter:
                            intellisenseJobRunner.InvokeAsync(() =>
                            {
                                DoComplete(false);
                            });

                            e.Handled = true;
                            break;
                    }
                }

                if (completionAssistant.IsVisible)
                {
                    if (!e.Handled)
                    {
                        switch (e.Key)
                        {
                            case Key.Down:
                                {
                                    completionAssistant.IncrementSignatureIndex();
                                    e.Handled = true;
                                }
                                break;

                            case Key.Up:
                                {
                                    completionAssistant.DecrementSignatureIndex();
                                    e.Handled = true;
                                }
                                break;
                        }
                    }
                }

                if (e.Key == Key.Escape)
                {
                    if (completionAssistant.IsVisible)
                    {
                        intellisenseJobRunner.InvokeAsync(() =>
                        {
                            Dispatcher.UIThread.InvokeAsync(() =>
                            completionAssistant.Close());
                        });
                    }
                    else if (intellisenseControl.IsVisible)
                    {
                        intellisenseJobRunner.InvokeAsync(() =>
                        {
                            CloseIntellisense();
                        });
                    }
                }
            }
        }
Exemple #19
0
 /// <summary>
 /// Called before the <see cref="KeyUp"/> event occurs.
 /// </summary>
 /// <param name="e">The event args.</param>
 protected virtual void OnKeyUp(KeyEventArgs e)
 {
 }
Exemple #20
0
        /// <inheritdoc/>
        protected override void OnKeyDown(KeyEventArgs e)
        {
            base.OnKeyDown(e);

            if (!e.Handled)
            {
                if (e.Key == Key.F4 ||
                    (e.Key == Key.Down && ((e.Modifiers & InputModifiers.Alt) != 0)))
                {
                    IsDropDownOpen = !IsDropDownOpen;
                    e.Handled = true;
                }
                else if (IsDropDownOpen && (e.Key == Key.Escape || e.Key == Key.Enter))
                {
                    IsDropDownOpen = false;
                    e.Handled = true;
                }
            }
        }
        public void OnKeyDown(KeyEventArgs e)
        {
            switch (e.Key)
            {
                //case Key.F9:
                //    DebugManager.StepInstruction();
                //    break;

                //case Key.F10:
                //    DebugManager.StepOver();
                //    break;

                //case Key.F11:
                //    DebugManager.StepInto();
                //    break;

                //case Key.F5:
                //    if (CurrentSolution?.StartupProject != null)
                //    {
                //        Debug(CurrentSolution.StartupProject);
                //    }
                //    break;

                case Key.F6:
                    Build();
                    break;
            }
        }
        private void PreProcessKeyboardInput(object sender, PreProcessInputEventArgs e)
        {
            if (e.Input.Device == this)
            {
                RawKeyEventArgs rawKeyEvent = e.Input as RawKeyEventArgs;

                if (rawKeyEvent != null)
                {
                    switch (rawKeyEvent.Type)
                    {
                        case RawKeyEventType.KeyDown:
                            KeyEventArgs ek = new KeyEventArgs(
                                (KeyboardDevice)rawKeyEvent.Device,
                                Mouse.PrimaryDevice.ActiveSource,
                                rawKeyEvent.Timestamp,
                                rawKeyEvent.Key);
                            ek.RoutedEvent = Keyboard.KeyDownEvent;
                            InputManager.Current.ProcessInput(ek);
                            e.Cancel();
                            break;
                    }
                }
            }
        }
        /// <summary>
        /// Handles the Alt/F10 keys being released in the window.
        /// </summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event args.</param>
        protected virtual void OnPreviewKeyUp(object sender, KeyEventArgs e)
        {
            switch (e.Key)
            {
                case Key.LeftAlt:
                    if (_ignoreAltUp)
                    {
                        _ignoreAltUp = false;
                    }
                    else if (_showingAccessKeys && MainMenu != null)
                    {
                        MainMenu.Open();
                        e.Handled = true;
                    }

                    break;

                case Key.F10:
                    _owner.ShowAccessKeys = _showingAccessKeys = true;
                    MainMenu.Open();
                    e.Handled = true;
                    break;
            }
        }
        /// <summary>
        /// Handles the Tab key being pressed in the window.
        /// </summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event args.</param>
        protected virtual void OnKeyDown(object sender, KeyEventArgs e)
        {
            var current = FocusManager.Instance.Current;

            if (current != null)
            {
                NavigationDirection? direction = null;

                switch (e.Key)
                {
                    case Key.Tab:
                        direction = (e.Modifiers & InputModifiers.Shift) == 0 ?
                            NavigationDirection.Next : NavigationDirection.Previous;
                        break;
                    case Key.Up:
                        direction = NavigationDirection.Up;
                        break;
                    case Key.Down:
                        direction = NavigationDirection.Down;
                        break;
                    case Key.Left:
                        direction = NavigationDirection.Left;
                        break;
                    case Key.Right:
                        direction = NavigationDirection.Right;
                        break;
                    case Key.PageUp:
                        direction = NavigationDirection.PageUp;
                        break;
                    case Key.PageDown:
                        direction = NavigationDirection.PageDown;
                        break;
                    case Key.Home:
                        direction = NavigationDirection.First;
                        break;
                    case Key.End:
                        direction = NavigationDirection.Last;
                        break;
                }

                if (direction.HasValue)
                {
                    Move(current, direction.Value, e.Modifiers);
                    e.Handled = true;
                }
            }
        }
Exemple #25
0
        /// <summary>
        /// Handle key down event for selection and copy.
        /// </summary>
        /// <param name="parent">the control hosting the html to invalidate</param>
        /// <param name="e">the pressed key</param>
        public void HandleKeyDown(Control parent, KeyEventArgs e)
        {
            ArgChecker.AssertArgNotNull(parent, "parent");
            ArgChecker.AssertArgNotNull(e, "e");

            _htmlContainerInt.HandleKeyDown(new ControlAdapter(parent), CreateKeyEevent(e));
        }
        protected override void OnKeyDown(KeyEventArgs e)
		{
			(DataContext as ShellViewModel)?.OnKeyDown(e);
		}
        private void ProcessRawEvent(RawInputEventArgs e)
        {
            IInputElement element = FocusedElement;

            if (element != null)
            {
                var keyInput = e as RawKeyEventArgs;

                if (keyInput != null)
                {
                    switch (keyInput.Type)
                    {
                        case RawKeyEventType.KeyDown:
                        case RawKeyEventType.KeyUp:
                            var routedEvent = keyInput.Type == RawKeyEventType.KeyDown
                                ? InputElement.KeyDownEvent
                                : InputElement.KeyUpEvent;

                            KeyEventArgs ev = new KeyEventArgs
                            {
                                RoutedEvent = routedEvent,
                                Device = this,
                                Key = keyInput.Key,
                                Modifiers = keyInput.Modifiers,
                                Source = element,
                            };

                            IVisual currentHandler = element;
                            while (currentHandler != null && !ev.Handled && keyInput.Type == RawKeyEventType.KeyDown)
                            {
                                var bindings = (currentHandler as IInputElement)?.KeyBindings;
                                if(bindings!=null)
                                    foreach (var binding in bindings)
                                    {
                                        if(ev.Handled)
                                            break;
                                        binding.TryHandle(ev);
                                    }
                                currentHandler = currentHandler.VisualParent;
                            }

                            element.RaiseEvent(ev);
                            e.Handled = ev.Handled;
                            break;
                    }
                }

                var text = e as RawTextInputEventArgs;

                if (text != null)
                {
                    var ev = new TextInputEventArgs()
                    {
                        Device = this,
                        Text = text.Text,
                        Source = element,
                        RoutedEvent = InputElement.TextInputEvent
                    };

                    element.RaiseEvent(ev);
                    e.Handled = ev.Handled;
                }
            }
        }
Exemple #28
0
        /// <summary>
        /// Called when a key is pressed within the menu.
        /// </summary>
        /// <param name="e">The event args.</param>
        protected override void OnKeyDown(KeyEventArgs e)
        {
            bool menuWasOpen = SelectedMenuItem?.IsSubMenuOpen ?? false;

            base.OnKeyDown(e);

            if (menuWasOpen)
            {
                // If a menu item was open and we navigate to a new one with the arrow keys, open
                // that menu and select the first item.
                var selection = SelectedMenuItem;

                if (selection != null && !selection.IsSubMenuOpen)
                {
                    selection.IsSubMenuOpen = true;
                    selection.SelectedIndex = 0;
                }
            }
        }
        /// <summary>
        /// Called when a key is pressed in the owner window.
        /// </summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event args.</param>
        protected virtual void OnPreviewKeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.LeftAlt)
            {
                _altIsDown = true;

                if (MainMenu == null || !MainMenu.IsOpen)
                {
                    // TODO: Use FocusScopes to store the current element and restore it when context menu is closed.
                    // Save currently focused input element.
                    _restoreFocusElement = FocusManager.Instance.Current;                    

                    // When Alt is pressed without a main menu, or with a closed main menu, show
                    // access key markers in the window (i.e. "_File").
                    _owner.ShowAccessKeys = _showingAccessKeys = true;
                }
                else
                {
                    // If the Alt key is pressed and the main menu is open, close the main menu.
                    CloseMenu();
                    _ignoreAltUp = true;

                    _restoreFocusElement?.Focus();
                    _restoreFocusElement = null;
                }

                // We always handle the Alt key.
                e.Handled = true;
            }
            else if (_altIsDown)
            {
                _ignoreAltUp = true;
            }
        }
Exemple #30
0
        /// <inheritdoc/>
        protected override void OnKeyDown(KeyEventArgs e)
        {
            if (!e.Handled)
            {
                switch (e.Key)
                {
                    case Key.Right:
                        if (Items != null && Items.Cast<object>().Any())
                        {
                            IsExpanded = true;
                        }

                        e.Handled = true;
                        break;

                    case Key.Left:
                        IsExpanded = false;
                        e.Handled = true;
                        break;
                }
            }

            base.OnKeyDown(e);
        }
        /// <summary>
        /// Called when a key is pressed in the owner window.
        /// </summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event args.</param>
        protected virtual void OnKeyDown(object sender, KeyEventArgs e)
        {
            bool menuIsOpen = MainMenu?.IsOpen == true;

            if (e.Key == Key.Escape && menuIsOpen)
            {
                // When the Escape key is pressed with the main menu open, close it.
                CloseMenu();
                e.Handled = true;
            }
            else if ((e.Modifiers & InputModifiers.Alt) != 0 || menuIsOpen)
            {
                // If any other key is pressed with the Alt key held down, or the main menu is open,
                // find all controls who have registered that access key.
                var text = e.Key.ToString().ToUpper();
                var matches = _registered
                    .Where(x => x.Item1 == text && x.Item2.IsEffectivelyVisible)
                    .Select(x => x.Item2);

                // If the menu is open, only match controls in the menu's visual tree.
                if (menuIsOpen)
                {
                    matches = matches.Where(x => MainMenu.IsVisualAncestorOf(x));
                }

                var match = matches.FirstOrDefault();

                // If there was a match, raise the AccessKeyPressed event on it.
                if (match != null)
                {
                    match.RaiseEvent(new RoutedEventArgs(AccessKeyPressedEvent));
                    e.Handled = true;
                }
            }
        }
Exemple #32
0
 public override void MoveCharacter(Avalonia.Input.KeyEventArgs pressed, int newPositionX = 0, int newPositionY = 0)
 {
     PositionOnArray = new Point(newPositionX + PositionOnArray.X, newPositionY + PositionOnArray.Y);
     DrawCharacter(new Point(PositionOnArray.X + newPositionX, PositionOnArray.Y + newPositionY), pressed);
 }
Exemple #33
0
 /// <summary>
 /// Create HtmlRenderer key event from Avalonia key event.
 /// </summary>
 private static RKeyEvent CreateKeyEevent(KeyEventArgs e)
 {
     var control = (e.Modifiers & InputModifiers.Control) == InputModifiers.Control;
     return new RKeyEvent(control, e.Key == Key.A, e.Key == Key.C);
 }
        /// <summary>
        /// Called when a key is pressed in the owner window.
        /// </summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event args.</param>
        protected virtual void OnPreviewKeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.LeftAlt)
            {
                if (MainMenu == null || !MainMenu.IsOpen)
                {
                    // When Alt is pressed without a main menu, or with a closed main menu, show
                    // access key markers in the window (i.e. "_File").
                    _owner.ShowAccessKeys = _showingAccessKeys = true;
                }
                else
                {
                    // If the Alt key is pressed and the main menu is open, close the main menu.
                    CloseMenu();
                    _ignoreAltUp = true;
                }

                // We always handle the Alt key.
                e.Handled = true;
            }
        }