Esempio n. 1
0
        public void Capture()
        {
            for (int i = 0; i < Bindings.Keys.Length; i++)
            {
                Binding key        = Bindings.Keys[i];
                bool    keyPressed = Input.GetKey(key.Code);
                if (keyPressed == key.State)
                {
                    continue;
                }
                Bindings.Keys[i].State = keyPressed;
                if (!keyPressed && !Release.Contains(key.InteractionSubscription))
                {
                    continue;
                }
                if (keyPressed && !Press.Contains(key.InteractionSubscription))
                {
                    continue;
                }
                Interaction interaction = keyPressed ? Interaction.Pressed : Interaction.Released;
                switch (key.Type)
                {
                case InputType.Key:
                    OnKeyEvent?.Invoke(new KeyEvent(interaction, key.Action));
                    break;

                case InputType.Mouse:
                    OnPointerEvent?.Invoke(new PointerEvent(interaction, key.Action, Input.mousePosition));
                    break;

                default:
                    throw new System.Exception("Unhandled input binding type: " + key.Type);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Makes a new instance of <see cref="GlfwKeyboard"/> class.
        /// </summary>
        /// <param name="window">Current context.</param>
        public GlfwKeyboard(GlfwWindow window)
        {
            handler = window;

            handler.OnRestore += Handler_OnRestore;

            keyCallback = (w, key, scancode, state, modifiers) =>
            {
                OnKeyEvent?.Invoke(this, new KeyboardKeyEventArgs
                {
                    Key       = (KeyboardKey)key,
                    Scancode  = scancode,
                    Action    = (KeyState)state,
                    Modifiers = (KeyModifier)modifiers
                });
            };

            charCallback = (w, c) =>
            {
                OnType?.Invoke(this, new KeyboardTypeEventArgs
                {
                    Point = (char)c
                });
            };

            charModsCallback = (w, c, modifiers) =>
            {
                OnTypeWithMods?.Invoke(this, new KeyboardModTypeEventArgs
                {
                    Point     = (char)c,
                    Modifiers = (KeyModifier)modifiers
                });
            };
        }
Esempio n. 3
0
        public static void OnKeyUp(Keys Key)
        {
            var Index = KeyToIndex(Key);

            KeyPreState_[Index] = KeyCurState_[Index];
            KeyCurState_[Index] = false;

            OnKeyEvent?.Invoke(Key, false);
        }
Esempio n. 4
0
        public static void OnKeyDown(Keys Key)
        {
            var Index = KeyToIndex(Key);

            KeyPreState_[Index] = KeyCurState_[Index];
            KeyCurState_[Index] = true;

            OnKeyEvent?.Invoke(Key, true);
        }
Esempio n. 5
0
        public InputMapper(Form form, Panel panel)
        {
            _stopwatch.Start();

            panel.MouseDown += (sender, args) =>
            {
                _isMouseDown = true;
                bool inDoubleClickInterval = _stopwatch.ElapsedMilliseconds < SystemInformation.DoubleClickTime;
                bool inDoubleClickDistance = Math.Abs(_lastClickPos.X - args.X) < SystemInformation.DoubleClickSize.Width &&
                                             Math.Abs(_lastClickPos.Y - args.Y) < SystemInformation.DoubleClickSize.Height;
                if (inDoubleClickInterval && inDoubleClickDistance)
                {
                    _clicks++;
                }
                else
                {
                    _clicks = 1;
                }
                _stopwatch.Restart();
                _lastClickPos = args.Location;
                OnMouseEvent?.Invoke(sender, new MouseEventItem(MouseEvent.MOUSE_PRESSED, args.X, args.Y, _clicks));
            };
            panel.MouseUp += (sender, args) =>
            {
                OnMouseEvent?.Invoke(sender, new MouseEventItem(MouseEvent.MOUSE_RELEASED, args.X, args.Y, _clicks));
                if (!_isDragging)
                {
                    OnMouseEvent?.Invoke(sender, new MouseEventItem(MouseEvent.MOUSE_CLICKED, args.X, args.Y, _clicks));
                }
                _isMouseDown = false;
                _isDragging  = false;
            };
            panel.MouseMove += (sender, args) =>
            {
                if (_isMouseDown && args.Location != _lastClickPos)
                {
                    _isDragging = true;
                    OnMouseEvent?.Invoke(sender, new MouseEventItem(MouseEvent.MOUSE_DRAGGED, args.X, args.Y, 0));
                }
            };
            form.KeyDown += (sender, args) =>
            {
                OnKeyEvent?.Invoke(sender, new KeyEventItem(KeyEvent.KEY_PRESSED, (int)args.KeyCode, KeyToChar(args)));
            };
            form.KeyPress += (sender, args) =>
            {
                OnKeyEvent?.Invoke(sender, new KeyEventItem(KeyEvent.KEY_TYPED, KeyEvent.VK_UNDEFINED, args.KeyChar));
            };
            form.KeyUp += (sender, args) =>
            {
                OnKeyEvent?.Invoke(sender, new KeyEventItem(KeyEvent.KEY_RELEASED, (int)args.KeyCode, KeyToChar(args)));
            };
        }
Esempio n. 6
0
    void Update()
    {
        if (Input.GetKeyDown(m_key))
        {
            m_down.Invoke(m_key);
        }
        if (Input.GetKeyUp(m_key))
        {
            m_up.Invoke(m_key);
        }

        if (Input.GetKey(m_key))
        {
            m_pressing.Invoke(m_key);
        }
    }
Esempio n. 7
0
        /// <summary>
        /// Update the state of this element
        /// </summary>
        /// <param name="DeltaTime">Game clock.</param>
        public void Update(IFrameBasedClock clock)
        {
            while (currentState != null && currentState.Events.Count > 0)
            {
                IInputEvent e = currentState.Events.Dequeue();

                if (e is InputEvent <KeyboardKeyEventArgs> keyEvent && keyEvent.Name == "OnKeyEvent")
                {
                    OnKeyEvent?.Invoke(this, keyEvent.Info);
                }

                if (e is InputEvent <KeyboardModTypeEventArgs> modEvent && modEvent.Name == "OnModType")
                {
                    OnTypeWithMods?.Invoke(this, modEvent.Info);
                }

                if (e is InputEvent <KeyboardTypeEventArgs> tyEvent && tyEvent.Name == "OnType")
                {
                    OnType?.Invoke(this, tyEvent.Info);
                }
            }
        }
Esempio n. 8
0
        public IntPtr LowLevelKeyboardProc(int nCode, IntPtr wParam, IntPtr lParam)
        {
            var fEatKeyStroke = false;

            var wparamTyped = wParam.ToInt32();

            if (Enum.IsDefined(typeof(KeyboardState), wparamTyped))
            {
                var o        = Marshal.PtrToStructure(lParam, typeof(LowLevelKeyboardInputEvent));
                var p        = (LowLevelKeyboardInputEvent)o;
                var keyState = (KeyboardState)wparamTyped;
                var keyUp    = keyState == KeyboardState.KeyUp || keyState == KeyboardState.SysKeyUp;
                var keyDown  = keyState == KeyboardState.KeyDown || keyState == KeyboardState.SysKeyDown;
                var key      = (System.Windows.Forms.Keys)p.VirtualCode;
                var state    = keyUp ? KeyboardKeyState.Up : keyDown ? KeyboardKeyState.Down : KeyboardKeyState.Unknown;
                Console.WriteLine("---");
                var flags = new LowLevelKeyboardInputEventFlags(p.Flags);
                OnKeyEvent?.Invoke(new KeyboardKey {
                    IsInjected = flags.IsInjected, Value = key, State = state
                });
            }

            return(fEatKeyStroke ? (IntPtr)1 : CallNextHookEx(IntPtr.Zero, nCode, wParam, lParam));
        }
Esempio n. 9
0
 private void KeyboardListener_KeyPressed(object sender, KeyboardEventArgs e)
 {
     _scene?.FireKeyEvent(e);
     OnKeyEvent?.Invoke(this, e);
 }