Example #1
0
 public override void KeyPressed(KeyConstant key, Scancode scancode, bool isRepeat)
 {
     if (key == KeyConstant.F)
     {
         Window.SetFullscreen(!Window.GetFullscreen());
     }
 }
Example #2
0
        /// <summary>
        /// Checks whether a certain <see cref="KeyConstant"/> is down. Not to be confused with <see cref="Scene.KeyPressed(KeyConstant, Scancode, bool)"/> or <see cref="Scene.KeyReleased(KeyConstant, Scancode)"/>.
        /// </summary>
        /// <param name="key">The key to check.</param>
        /// <returns>True if the key is down, false if not.</returns>
        public static bool IsDown(KeyConstant key)
        {
            bool out_result = false;

            Love2dDll.wrap_love_dll_keyboard_isDown((int)key, out out_result);
            return(out_result);
        }
Example #3
0
 public override void KeyReleased(KeyConstant key, Scancode scancode)
 {
     if (key == KeyConstant.Escape)
     {
         Event.Quit();
     }
 }
Example #4
0
 public override void KeyPressed(KeyConstant key, Scancode scancode, bool isRepeat)
 {
     if (Keyboard.IsPressed(KeyConstant.C) && (Keyboard.IsDown(KeyConstant.LCtrl) || Keyboard.IsDown(KeyConstant.RCtrl)))
     {
         Special.SetClipboardText(errorMsg);
     }
 }
Example #5
0
        /// <summary>
        /// Gets the hardware scancode corresponding to the given key.
        /// <para>Unlike <see cref="KeyConstant"/>, <see cref="Scancode"/> are keyboard layout-independent. For example the scancode "w" will be generated if the key in the same place as the "w" key on an American keyboard is pressed, no matter what the key is labelled or what the user's operating system settings are.</para>
        /// <para><see cref="Scancode"/> are useful for creating default controls that have the same physical locations on on all systems.</para>
        /// </summary>
        /// <param name="key">The key to get the scancode from.</param>
        /// <returns>The scancode corresponding to the given key, or "unknown" if the given key has no known physical representation on the current system.</returns>
        public static Scancode GetScancodeFromKey(KeyConstant key)
        {
            int out_scancode_type = 0;

            Love2dDll.wrap_love_dll_keyboard_getScancodeFromKey((int)key, out out_scancode_type);
            return((Scancode)out_scancode_type);
        }
Example #6
0
 internal static IIDXAction FromKeyConstant(this KeyConstant key)
 {
     try {
         return(Input.Actions[key]);
     } catch (Exception e) {
         return(IIDXAction.Blank);
     }
 }
Example #7
0
            public void KeyReleased(KeyConstant key, Scancode scancode)
            {
                EventData ed = new EventData(EventType.KeyReleased);

                ed.key      = key;
                ed.scancode = scancode;
                list.AddLast(ed);
            }
Example #8
0
            public void KeyPressed(KeyConstant key, Scancode scancode, bool isRepeat)
            {
                EventData ed = new EventData(EventType.KeyPressed);

                ed.key      = key;
                ed.scancode = scancode;
                ed.flag     = isRepeat;
                list.AddLast(ed);
            }
Example #9
0
 public override void KeyPressed(KeyConstant key, Scancode scancode, bool isRepeat)
 {
     if (key == KeyConstant.N)
     {
         currentTest = LoadTests();
         currentTest.LoadWorld();
         currentTest.Load();
         currentTest.ResetTranslation();
     }
 }
Example #10
0
        public void KeyPressed(KeyConstant key, Scancode scancode, bool isRepeat)
        {
            switch (scancode)
            {
            case Scancode.Number1:
                CurrentGunIndex = 0;
                break;

            case Scancode.Number2:
                CurrentGunIndex = 1;
                break;
            }
        }
Example #11
0
        public override void KeyPressed(KeyConstant key, Scancode scancode, bool isRepeat)
        {
            base.KeyPressed(key, scancode, isRepeat);

            if (key == KeyConstant.Right)
            {
                Zoom += 1;
            }
            if (key == KeyConstant.Left)
            {
                Zoom = Math.Max(Zoom - 1, 1);
            }
        }
Example #12
0
 public EventData(EventType t)
 {
     type          = t;
     key           = KeyConstant.Unknown;
     scancode      = Scancode.Unknow;
     joystick      = null;
     direction     = JoystickHat.Centered;
     gamepadButton = GamepadButton.A;
     gamepadAxis   = GamepadAxis.LeftX;
     text          = null;
     flag          = false;
     fx            = 0;
     fy            = 0;
     fz            = 0;
     fw            = 0;
     fp            = 0;
     idx           = 0;
     idy           = 0;
     lid           = 0;
 }
Example #13
0
        public override void KeyPressed(KeyConstant key, Scancode scancode, bool isRepeat)
        {
            base.KeyPressed(key, scancode, isRepeat);

            switch (key)
            {
            case KeyConstant.Right:
                Zoom += 1;
                break;

            case KeyConstant.Left:
                Zoom = Math.Max(Zoom - 1, 1);
                break;

            case KeyConstant.R:
                Zoom      = 8;
                Intensity = 2;
                break;
            }
        }
Example #14
0
 public static bool IsKeyboardDown(KeyConstant key)
 {
     return(currentKeyboard.Contains(key));
 }
Example #15
0
 internal void InvokeKeyPressed(KeyConstant key, Scancode scancode, bool isRepeat)
 {
     OnKeyPressed?.Invoke(key, scancode, isRepeat);
     KeyPressed(key, scancode, isRepeat);
 }
Example #16
0
 /// <summary>
 /// Triggered when a keyboard key is released.
 /// </summary>
 /// <param name="key">Character of the pressed key.</param>
 /// <param name="scancode">The scancode representing the pressed key.</param>
 public virtual void KeyReleased(KeyConstant key, Scancode scancode)
 {
 }
Example #17
0
        public override void KeyPressed(KeyConstant key, Scancode scancode, bool isRepeat)
        {
            base.KeyPressed(key, scancode, isRepeat);

            switch (key)
            {
            case KeyConstant.Right:
                horizontal_smoothness++;
                break;

            case KeyConstant.Left:
                if (horizontal_smoothness > 1)
                {
                    horizontal_smoothness--;
                }
                break;

            case KeyConstant.Down:
                if (vertical_smoothness > 1)
                {
                    vertical_smoothness--;
                    for (int i = 0; i < smooth.Count; i++)
                    {
                        smooth.RemoveAt(i);
                    }
                }
                break;

            case KeyConstant.Up:
                vertical_smoothness++;
                for (int i = 0; i < smooth.Count; i++)
                {
                    smooth.RemoveAt(i);
                }
                break;

            case KeyConstant.H:
                smoothType = SmoothType.horizontal;
                break;

            case KeyConstant.V:
                smoothType = SmoothType.vertical;
                break;

            case KeyConstant.B:
                smoothType = SmoothType.both;
                break;

            case KeyConstant.Number1:
                vis_mode = 0;
                break;

            case KeyConstant.Number2:
                vis_mode = 1;
                break;

            case KeyConstant.Number3:
                vis_mode = 2;
                break;

            case KeyConstant.Number4:
                vis_mode = 3;
                break;

            case KeyConstant.Number5:
                vis_mode = 4;
                break;

            case KeyConstant.Number6:
                vis_mode = 5;
                break;

            case KeyConstant.Number7:
                vis_mode = 6;
                break;

            case KeyConstant.Number8:
                vis_mode = 7;
                break;

            case KeyConstant.Number9:
                vis_mode = 8;
                break;

            case KeyConstant.Number0:
                vis_mode = 9;
                break;
            }
        }
Example #18
0
 public override void KeyPressed(KeyConstant key, Scancode scancode, bool is_repeat) => Elements.CallFocus("KeyPressed", key, scancode, is_repeat);
Example #19
0
 internal void InvokeKeyReleased(KeyConstant key, Scancode scancode)
 {
     OnKeyReleased?.Invoke(key, scancode);
     KeyReleased(key, scancode);
 }
Example #20
0
 public override void KeyPressed(KeyConstant key, Scancode scancode, bool isRepeat)
 {
     Player.KeyPressed(key, scancode, isRepeat);
 }
Example #21
0
 public override void KeyPressed(KeyConstant key, Scancode scancode, bool isRepeat) => behc.OnKeyPressed?.Invoke(key, scancode, isRepeat);
Example #22
0
        /// <summary>
        /// Checks whether a certain key is released.
        /// </summary>
        /// <param name="key">The key to check.</param>
        public bool IsReleased(KeyConstant key)
        {
            int index = (int)key;

            return(lastKeyStates[index] == true && keyStates[index] == false);
        }
Example #23
0
 public override void KeyReleased(KeyConstant key, Scancode scancode) => behc.OnKeyReleased?.Invoke(key, scancode);
Example #24
0
        public override void KeyPressed(KeyConstant key, Scancode scancode, bool is_repeat)
        {
            //Console.WriteLine( key );

            //  > Control keys
            if (Keyboard.IsDown(KeyConstant.LCtrl))
            {
                //  > Save
                if (Keyboard.IsDown(KeyConstant.S))
                {
                    Save();
                }
                //  > Paste
                else if (Keyboard.IsDown(KeyConstant.V))
                {
                    string text = Clipboard.GetText();
                    Append(text);

                    if (!text.Contains("\n"))
                    {
                        MoveCursorTowards(text.Length, 0);
                    }
                }
            }
            //  > Alt Keys
            else if (Keyboard.IsDown(KeyConstant.LAlt))
            {
                //  > Swap lines
                if (Keyboard.IsDown(KeyConstant.Up))
                {
                    SwapLine(-1);
                }
                else if (Keyboard.IsDown(KeyConstant.Down))
                {
                    SwapLine(1);
                }
            }
            //  > Single keys
            else
            {
                switch (key)
                {
                //  > Cursor Movements
                case KeyConstant.Up:
                    MoveCursorTowards(0, -1);
                    break;

                case KeyConstant.Down:
                    MoveCursorTowards(0, 1);
                    break;

                case KeyConstant.Left:
                    MoveCursorTowards(-1, 0);
                    break;

                case KeyConstant.Right:
                    MoveCursorTowards(1, 0);
                    break;

                //  > Editing
                case KeyConstant.Enter:
                    //  > Create new line with text
                    Lines.Insert(Cursor.Y + 1, Lines[Cursor.Y].Substring(Cursor.X));

                    //  > Remove old text
                    Lines[Cursor.Y] = Lines[Cursor.Y].Substring(0, Cursor.X);

                    //  > Set cursor pos to new line
                    SetCursorPos(0, Cursor.Y + 1);
                    break;

                case KeyConstant.KeypadEnter:
                    KeyPressed(KeyConstant.Enter, scancode, is_repeat);
                    break;

                case KeyConstant.Tab:
                    var n = 4;
                    Lines[Cursor.Y] = Lines[Cursor.Y].Insert(Cursor.X, new String(' ', n));
                    MoveCursorTowards(n, 0);
                    break;

                case KeyConstant.Backspace:
                    //  > Remove line
                    if (Cursor.X == 0)
                    {
                        if (Cursor.Y > 0)
                        {
                            int new_x = Lines[Cursor.Y - 1].Length;
                            Lines[Cursor.Y - 1] = Lines[Cursor.Y - 1].Insert(Lines[Cursor.Y - 1].Length, Lines[Cursor.Y]);
                            Lines.RemoveAt(Cursor.Y);
                            SetCursorPos(new_x, Cursor.Y - 1);
                        }
                    }
                    //  > Remove chars
                    else
                    {
                        Lines[Cursor.Y] = Lines[Cursor.Y].Remove(Cursor.X - 1, 1);
                        MoveCursorTowards(-1, 0);
                    }

                    break;

                case KeyConstant.Delete:
                    //  > Remove line
                    if (Cursor.X == Lines[Cursor.Y].Length)
                    {
                        if (Cursor.Y < Lines.Count - 1)
                        {
                            Lines[Cursor.Y] = Lines[Cursor.Y].Insert(Lines[Cursor.Y].Length, Lines[Cursor.Y + 1]);
                            Lines.RemoveAt(Cursor.Y + 1);
                        }
                    }
                    //  > Remove chars
                    else
                    {
                        Lines[Cursor.Y] = Lines[Cursor.Y].Remove(Cursor.X, 1);
                    }

                    break;

                //  > Run
                case KeyConstant.F5:
                    if (!Children.Contains(RunButton))
                    {
                        return;
                    }
                    Save();
                    Run();
                    break;
                }
            }
        }
Example #25
0
 public virtual void KeyPressed(KeyConstant key, Scancode scancode, bool isRepeat)
 {
 }
Example #26
0
 public static bool IsKeyboardPrevious(KeyConstant key)
 {
     return(lastKeyboard.Contains(key));
 }
Example #27
0
 public override void KeyPressed(KeyConstant key, Scancode scancode, bool isRepeat) => ActiveScene?.ActionStarted(new InputEventArgs(key.FromKeyConstant(), 0f));