Exemplo n.º 1
0
 void OnKeyDown(Object o, KeyboardEventArgs e)
 {
     UpdateKeyState(e, true);
     keyEvent(e, true);
     //if (HandleFrameworkKey(e)) return;
     //game.ProcessKey(e, true);
 }
Exemplo n.º 2
0
        void UpdateKeyState(KeyboardEventArgs e, bool press)
        {
            if (e.PlatformKeyCode <= 255)
            {
                platformKeys[e.PlatformKeyCode] = press;
            }

            if (e.Key <= 100)
            {
                keys[e.Key] = press;
            }
        }
Exemplo n.º 3
0
        private void cmdline_KeyDownEvent(object e, KeyboardEventArgs k)
        {
            if (!InTutorialMode && k.KeyboardDevice.IsKeyDown(Key.Enter))
            {
                if (IsExitCommand(txtCmdLine.Text))
                {
                    CmdInvoker.CleanUp();
                    Application.Current.Shutdown();
                }
                else if (txtCmdLine.Text.StartsWith("wiggle"))
                {
                    wiggle();
                    txtCmdLine.Text = "";
                    return;
                }

                GGResult result = CmdInvoker.InvokeCommand(txtCmdLine.Text);
                HandleCmd(result);
                /*
                BackgroundWorker bw = new BackgroundWorker();
                bw.DoWork += BW_DoWork;
                bw.RunWorkerCompleted += BW_Completed;
                bw.RunWorkerAsync(txtCmdLine.Text);
                HistoryList.Add(txtCmdLine.Text);*/
                if (HistoryList.Count > 10) HistoryList.RemoveAt(0);
                HistoryListIndex = 0;
                txtCmdLine.Text = "";
            }
        }
Exemplo n.º 4
0
        private void txtbox_PreviewKeyDownEvent(object e, KeyboardEventArgs k)
        {
            int inscreen = 0, rexit = txtShift, lexit = -txtShift, duration = 1000;

            if (IsDown(vkKey(ScrollHotkey)) && k.KeyboardDevice.IsKeyDown(Key.Right))
            {
                MoveX(RTBNow, inscreen, lexit, duration);

                PurgeDeletedLists();

                RTBIndex = GetNextIndex();
                RTBNow = RTBArray[RTBIndex];

                MoveX(RTBNow, rexit, inscreen, duration);
                if(!InTutorialMode)RefreshContents(RTBIndex);

            }
            else if (IsDown(vkKey(ScrollHotkey)) && k.KeyboardDevice.IsKeyDown(Key.Left))
            {

                MoveX(RTBNow, inscreen, rexit, duration);
                PurgeDeletedLists();

                RTBIndex = GetPrevIndex();
                RTBNow = RTBArray[RTBIndex];

                MoveX(RTBNow, lexit, inscreen, duration);

                if (!InTutorialMode) RefreshContents(RTBIndex);

            }
            else if (IsDown(vkKey(ScrollHotkey)) && k.KeyboardDevice.IsKeyDown(Key.Down))
            {
                RTBNow.LineDown();

            }
            else if (IsDown(vkKey(ScrollHotkey)) && k.KeyboardDevice.IsKeyDown(Key.Up))
            {
                RTBNow.LineUp();

            }
            else if (k.KeyboardDevice.IsKeyDown(Key.Down))
            {
                if (HistoryList.Count > 0)
                {
                    HistoryListIndex = (HistoryListIndex - 1) < 0 ? HistoryList.Count - 1 : HistoryListIndex - 1;
                    txtCmdLine.Text = HistoryList[HistoryListIndex];
                    txtCmdLine.CaretIndex = txtCmdLine.Text.Length;
                }
            }
            else if (k.KeyboardDevice.IsKeyDown(Key.Up))
            {
                if (HistoryList.Count > 0)
                {
                    txtCmdLine.Text = HistoryList[HistoryListIndex];
                    HistoryListIndex = (HistoryListIndex + 1) % HistoryList.Count;
                    txtCmdLine.CaretIndex = txtCmdLine.Text.Length;
                }
            }
        }
Exemplo n.º 5
0
        public void ProcessKey(KeyboardEventArgs e, bool pressed)
        {
            if (pressed) return;

            if (e.Key == 36) // G == grid
            {
                if (gridEnabled) DisableGrid(); else EnableGrid();
            }
            if (e.Key == 35) // F == freeze
            {
                if (frozen)
                {
                    frozen = false;
                    game.DisableSimulation();
                }
                else
                {
                    frozen = true;
                    game.EnableSimulation();
                }
            }
            if (e.Key == 47) // R = render XAML
            {
                RenderWorldXAML();
            }
            if (e.Key == 43) // N == names
            {
                names = !names;
                if (!names) HideNames(); else ShowNames();
            }
            if (e.Key == 13 || e.Key == 20) // HOME or 0
            {
                ResetScrollPane();
            }
            if (e.Key == 12 || e.Key == 29) // END = reset zoom or 9
            {
                ResetZoom();
            }
            if (e.Key == 19 || e.PlatformKeyCode == 46) // DELETE (need to use PlatformKeyCode on windows)
            {
                // delete selected objects
                foreach (IGizmo gizmo in currentGizmos)
                {
                    if (gizmo is MoveGizmo) DeleteObject(gizmo as MoveGizmo);
                    gizmo.Destroy();
                }
                currentGizmos.Clear();
                dragGizmos.Clear();
            }

            if (e.Ctrl && e.Key == 32) // CTRL+C == copy
            {
                CopySelectionIntoClipboard();
            }
            if (e.Ctrl && e.Key == 51) // CTRL+V == paste
            {
                PasteSelectionFromClipboard();
            }
        }
Exemplo n.º 6
0
        public void ProcessKey(KeyboardEventArgs e, bool pressed)
        {
            // handle editor behavior
            if (editor.Active) editor.ProcessKey(e, pressed);

            // no key processing in game ...
        }
Exemplo n.º 7
0
 void OnKeyUp(Object o, KeyboardEventArgs e)
 {
     UpdateKeyState(e, false);
     keyEvent(e, false);
     //game.ProcessKey(e, false);
 }
Exemplo n.º 8
0
 private void MainWindow_OnKeyDown(object sender, KeyboardEventArgs e)
 {
     if (Keyboard.IsKeyDown(Key.A) && _player1.Y - _padSpeed >= 0) _player1.Y -= _padSpeed;
     if (Keyboard.IsKeyDown(Key.Z) && _player1.Y + _padSpeed <= MainCanvas.ActualHeight - _player1.PadLength)
         _player1.Y += _padSpeed;
     if (Keyboard.IsKeyDown(Key.Up) && _player2.Y - _padSpeed >= 0) _player2.Y -= _padSpeed;
     if (Keyboard.IsKeyDown(Key.Down) && _player2.Y + _padSpeed <= (MainCanvas.ActualHeight - _player2.PadLength))
         _player2.Y += _padSpeed;
 }
Exemplo n.º 9
0
 void KeyPress(KeyboardEventArgs e, bool down)
 {
     if (down && HandleFrameworkKey(e)) return;
     game.ProcessKey(e, down);
 }
Exemplo n.º 10
0
        public bool HandleFrameworkKey(KeyboardEventArgs e)
        {
            if (anyKeyRestart)
            {
                RestartLevel();
                return true;
            }

            if (e.Key == 2 || e.PlatformKeyCode == 192 || e.Key == 46) // TAB or Q
            {
                currentLevel++;
                if (currentLevel >= levels.Length) currentLevel = 0;

                SwitchLevel(levels[currentLevel]);
                return true;
            }

            if (e.Key == 3) // ENTER
            {
                RestartLevel();
                return true;
            }

            if (e.Key == 9) // SPACE
            {
                if (game.editor.Active)
                {
                    game.DisableEditor();
                }
                else
                {
                    game.EnableEditor();
                }
                return true;
            }

            if (e.Key == 56 || e.Key == 21) // F1
            {
                help.Visible = !help.Visible;
                return true;
            }

            if (e.Key == 57 || e.Key == 22) // F2
            {
                stats.Visible = !stats.Visible;
                return true;
            }

            if (e.Key == 59 || e.Key == 58 || e.Key == 23 || e.Key == 24) // F4 or F3 (for IE)
            {
                OpenScriptEditor();
                return true;
            }

            return false;
        }
Exemplo n.º 11
0
 // Function, when a component lost the focus
 /// <summary>
 /// A component lost the focus. Two functions are triggerd in that case:
 /// 1. Remove dashed line around the component canvas
 /// 2. Deactivate several buttons in the ribbon menu (move, delete, properties)
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void ComponentCanvas_LostKeyboardFocus(object sender, KeyboardEventArgs e)
 {
     Canvas focusCanvas = (Canvas)sender;
     Canvas.SetZIndex(focusCanvas, Canvas.GetZIndex(focusCanvas) - 3000);
     focusedComponent = null;
     foreach (UIElement uie in focusCanvas.Children) {
         if ((uie is Rectangle) && (((Rectangle)uie).Name.Equals("keyboardFocusRectangle"))) {
             focusCanvas.Children.Remove((Rectangle)uie);
             moveComponentRibbonButton.IsEnabled = false;
             //deleteComponentRibbonButton.IsEnabled = false;
             componentPropertiesRibbonButton.IsEnabled = false;
             moveComponentRibbonButton.IsChecked = false;
             break;
         }
     }
 }
Exemplo n.º 12
0
        /// <summary>
        /// A component got the focus. Several functions are triggerd in that case:
        /// 1. Dashed line around the component canvas
        /// 2. Activate several buttons in the ribbon menu (move, delete, properties)
        /// 3. Set the property editors in the property-dock (by calling SetPropertyDock(modelComponent tempComponent))
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void ComponentCanvas_GotKeyboardFocus(object sender, KeyboardEventArgs e)
        {
            Canvas focusCanvas = (Canvas)sender;
            bool abort = false;
            foreach (UIElement uie in focusCanvas.Children) {
                if ((uie is Rectangle) && (((Rectangle)uie).Name.Equals("keyboardFocusRectangle"))) {
                    abort = true;
                    break;
                }
            }
            if (!abort) {
                double canvasX = Canvas.GetLeft(focusCanvas);
                double canvasY = Canvas.GetTop(focusCanvas);
                //focusCanvas.Background = new SolidColorBrush(Colors.Red);

                Rectangle cr = new Rectangle();
                cr.Stroke = new SolidColorBrush(Colors.Blue);
                cr.StrokeThickness = 2;
                /*DoubleCollection dashes = new DoubleCollection();
                dashes.Add(1.0000001);
                dashes.Add(2.0000001);
                cr.StrokeDashArray = dashes;*/
                cr.Width = focusCanvas.Width;
                cr.Height = focusCanvas.Height;
                focusCanvas.Children.Add(cr);
                Canvas.SetTop(cr, 0);
                Canvas.SetLeft(cr, 0);
                cr.Name = "keyboardFocusRectangle";
                cr.RadiusX = 4;
                cr.RadiusY = 4;
            }
            Canvas.SetZIndex(focusCanvas, Canvas.GetZIndex(focusCanvas) + 3000);

            moveComponentRibbonButton.IsEnabled = true;
            //deleteComponentRibbonButton.IsEnabled = true;
            componentPropertiesRibbonButton.IsEnabled = true;

            componentType tempComponent = null;
            foreach (componentType tempComponent2 in deploymentComponentList.Values) {
                if (tempComponent2.ComponentCanvas == (Canvas)sender) {
                    tempComponent = tempComponent2;
                    break;
                }
            }
            focusedComponent = tempComponent;
            SetPropertyDock(tempComponent);
        }
Exemplo n.º 13
0
 public virtual void KeyUp(KeyboardEventArgs e)
 {
 }
Exemplo n.º 14
0
 public virtual void KeyDown(KeyboardEventArgs e)
 {
 }
Exemplo n.º 15
0
 public void KeyUp(KeyboardEventArgs e)
 {
     if (tool != null)
     {
         tool.KeyUp(e);
     }
 }
Exemplo n.º 16
0
 private void MainWindow_OnKeyDown(object sender, KeyboardEventArgs e)
 {
     if (Keyboard.IsKeyDown(Key.Left) && _BottomPad.XPosition >= 0) _BottomPad.XPosition -= _HumanPadSpeed;
     if (Keyboard.IsKeyDown(Key.Right) && _BottomPad.XPosition <= AreaRight - 60) _BottomPad.XPosition += _HumanPadSpeed;
     if (Keyboard.IsKeyDown(Key.N)) NewGame();
     if (Keyboard.IsKeyDown(Key.P)) PauseGame();
 }
Exemplo n.º 17
0
 /// <summary>
 /// Handle the KeyDown event for the main window.
 /// </summary>
 /// <param name="sender">Event sender.</param>
 /// <param name="e">Event arguments.</param>
 private void mainWindow_KeyDown(object sender, KeyboardEventArgs e)
 {
     // Pan 10% of the canvas width or height.
     if ( e.KeyboardDevice.IsKeyDown(Key.Left) )
         this.shapeDisplay.Pan(0.10, 0);
     else if ( e.KeyboardDevice.IsKeyDown(Key.Right) )
         this.shapeDisplay.Pan(-0.10, 0);
     else if ( e.KeyboardDevice.IsKeyDown(Key.Up) )
         this.shapeDisplay.Pan(0, 0.10);
     else if ( e.KeyboardDevice.IsKeyDown(Key.Down) )
         this.shapeDisplay.Pan(0, -0.10);
 }
Exemplo n.º 18
0
        void Page_KeyUp(object sender, KeyboardEventArgs e)
        {
            switch(e.Key)
            {
                case 14:
                    _grid.PanLeft();
                    break;
                case 16:
                    _grid.PanRight();
                    break;
                case 15:
                    ZoomIn();
                    break;
                case 17:
                    ZoomOut();
                    break;

            }
        }