Exemplo n.º 1
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
                });
            };
        }
Exemplo n.º 2
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);
                }
            }
        }