Пример #1
0
        public virtual void OnKeyPress(KeyPressEventArgs e)
        {
            if (!_enabled)
            {
                return;
            }

            if (Controls != null)
            {
                for (int i = Controls.Count - 1; i >= 0; i--)
                {
                    if (e.Handled)
                    {
                        return;
                    }
                    else
                    {
                        Controls[i].OnKeyPress(e);
                    }
                }
            }

            if (KeyPress == null)
            {
                return;
            }
            KeyPress.Invoke(this, e);
        }
Пример #2
0
        protected virtual void OnKeyPressCore(KeyPressEventArgs args)
        {
            if (args == null || args.Cancel)
            {
                return;
            }

            KeyPress?.Invoke(this, args);

            if (args.Cancel)
            {
                return;
            }

            foreach (var keyPress in Renderables.OfType <ISupportKeyPress>())
            {
                keyPress.OnKeyPress(args);
                if (args.Cancel)
                {
                    return;
                }
            }

            if (RefreshKeyHit(args))
            {
                return;
            }
        }
 private void KeyPressVoid()
 {
     while (true)
     {
         KeyPress?.Invoke(Console.ReadKey(true));
     }
 }
Пример #4
0
        private void CoreWindow_KeyDown(CoreWindow sender, KeyEventArgs args)
        {
            var keys = BuildKeyData(args.VirtualKey, true);

            //KeyDown?.Invoke(null, new OpenKeyEventArgs(keys));
            KeyPress?.Invoke(null, new OpenKeyEventArgs(keys));
        }
Пример #5
0
        private void OnInternalKeyPress(object sender, OpenTK.KeyPressEventArgs e)
        {
            var args = new KeyboardPressEventArgs(e.KeyChar);

            OnKeyPress(this, args);
            KeyPress?.Invoke(this, args);
        }
Пример #6
0
        public virtual void OnKeyPress(KeyPressEventArgs e)
        {
            if (!_Enabled)
            {
                return;
            }

            if (Controls != null)
            {
                for (int I = Controls.Count - 1; I >= 0; I--)
                {
                    if (e.Handled)
                    {
                        return;
                    }
                    else
                    {
                        Controls[I].OnKeyPress(e);
                    }
                }
            }

            if (KeyPress != null)
            {
                KeyPress.Invoke(this, e);
                return;
            }
        }
Пример #7
0
        private IntPtr KeyHookProc(int nCode, IntPtr wParam, IntPtr lParam)
        {
            Hook.KBDLLHOOKSTRUCT   hs = (Hook.KBDLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(Hook.KBDLLHOOKSTRUCT));
            Message.WindowsMessage wm = (Message.WindowsMessage)wParam;
            if (nCode >= 0 && (_key == 0 || _key == hs.vkCode))
            {
                Keyboard.VirtualKeyStates key      = (Keyboard.VirtualKeyStates)hs.vkCode;
                Keyboard.ScanCodes        scanCode = (Keyboard.ScanCodes)hs.scanCode;
                KeyboardState.KeyStatus   status;
                switch (wm)
                {
                case Message.WindowsMessage.KEYDOWN:
                case Message.WindowsMessage.SYSKEYDOWN:
                    status = KeyboardState.KeyStatus.Down;
                    break;

                case Message.WindowsMessage.KEYUP:
                case Message.WindowsMessage.SYSKEYUP:
                    status = KeyboardState.KeyStatus.Up;
                    break;

                default:
                    status = KeyboardState.KeyStatus.None;
                    break;
                }
                TimeSpan      time = TimeSpan.FromMilliseconds(hs.time);
                KeyboardState ks   = KeyboardState.CreateCurrent(key, scanCode, status, time);
                switch (ks.Status)
                {
                case KeyboardState.KeyStatus.Down:
                    KeyAny?.Invoke(this, ks);
                    KeyPress?.Invoke(this, ks);
                    KeyDown?.Invoke(this, ks);
                    break;

                case KeyboardState.KeyStatus.Hold:
                    KeyAny?.Invoke(this, ks);
                    KeyPress?.Invoke(this, ks);
                    KeyHold?.Invoke(this, ks);
                    break;

                case KeyboardState.KeyStatus.Up:
                    KeyAny?.Invoke(this, ks);
                    KeyUp?.Invoke(this, ks);
                    break;

                default:
                    KeyAny?.Invoke(this, ks);
                    break;
                }
                if (CallNextHook is null || CallNextHook(this, ks))
                {
                    return(Hook.CallNextHookEx(_kHHook, nCode, wParam, lParam));
                }
                else
                {
                    return(_kHHook);
                }
            }
Пример #8
0
 private void Key_Down(VKey key)
 {
     if (!pressedKeys.Contains(key))
     {
         pressedKeys.Add(key);
         KeyPress?.Invoke(key, pressedKeys);
     }
     KeyDown?.Invoke(key, pressedKeys);
 }
Пример #9
0
        internal Keyboard(Window window)
        {
            Window = window;

            Glfw.SetKeyCallback(window.Handle, (sender, key, scancode, action, mods) =>
                KeyPress?.Invoke(Window.WindowFromHandle(sender), (Key) key, scancode, (KeyAction) action, (ModKey) mods));

            Glfw.SetCharCallback(window.Handle, (sender, codepoint) => CharPress?.Invoke(Window.WindowFromHandle(sender), (char) codepoint));
        }
Пример #10
0
        private void HookManager_KeyPress(object sender, KeyPressEventArgs e)
        {
            var ext = e as KeyPressEventArgsExt;

            if (ext != null)
            {
                KeyPress?.Invoke(e.KeyChar, ext.Code);
            }
        }
Пример #11
0
        internal bool PerformKeyPress(Viewport viewport, KeyPressEvent e)
        {
            var handled = OnKeyPress(viewport, e);

            if (!handled)
            {
                KeyPress?.Invoke(this, viewport, e, ref handled);
            }
            return(handled);
        }
Пример #12
0
        void GameWindow_KeyDown(object sender, KeyboardKeyEventArgs e)
        {
            var key = KeyMapper.GetMap(e.Key);

            if (key == VirtualKeyCode.NoKey)
            {
                return; // If there is no corresponding key mapping, we can't do anything about it.
            }
            KeyPress?.Invoke(this, new KeyboardEventArgs(key));
        }
Пример #13
0
        private void Gc_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
        {
            if (EnsureCurrent)
            {
                glControl.MakeCurrent();
            }
            GLKeyEventArgs ka = new GLKeyEventArgs(e.KeyChar);

            KeyPress?.Invoke(this, ka);
        }
Пример #14
0
 public void Invoke(string EventName, Game CurrentGame, EventArguments Args)
 {
     if (EventName == "Closing")
     {
         Closing.Invoke(CurrentGame, Args);
     }
     if (EventName == "KeyDown")
     {
         KeyDown.Invoke(CurrentGame, Args);
     }
     if (EventName == "KeyUp")
     {
         KeyUp.Invoke(CurrentGame, Args);
     }
     if (EventName == "KeyPress")
     {
         KeyPress.Invoke(CurrentGame, Args);
     }
     if (EventName == "Load")
     {
         Load.Invoke(CurrentGame, Args);
     }
     if (EventName == "MouseDown")
     {
         MouseDown.Invoke(CurrentGame, Args);
     }
     if (EventName == "MouseUp")
     {
         MouseUp.Invoke(CurrentGame, Args);
     }
     if (EventName == "MouseClick")
     {
         MouseClick.Invoke(CurrentGame, Args);
     }
     if (EventName == "MouseMove")
     {
         MouseMove.Invoke(CurrentGame, Args);
     }
     if (EventName == "MouseWheel")
     {
         MouseWheel.Invoke(CurrentGame, Args);
     }
     if (EventName == "RenderFrame")
     {
         RenderFrame.Invoke(CurrentGame, Args);
     }
     if (EventName == "Resize")
     {
         Resize.Invoke(CurrentGame, Args);
     }
     if (EventName == "TimerTick")
     {
         TimerTick.Invoke(CurrentGame, Args);
     }
 }
Пример #15
0
        private IntPtr CaptureKey(int nCode, IntPtr wp, IntPtr lp)
        {
            if (nCode >= 0)
            {
                var objKeyInfo = (KbDllHookStruct)Marshal.PtrToStructure(lp, typeof(KbDllHookStruct));

                KeyPress?.Invoke(this, new KeyEventArgs(objKeyInfo.key));
            }

            return(CallNextHookEx(_ptrHook, nCode, wp, lp));
        }
Пример #16
0
        internal static void InvokePress(KeyInfo info)
        {
            //System.Diagnostics.Debug.Assert(heldKeys.Add(info.KeyCode), "added a key which was pressed");
            if (!heldKeys.Add(info.KeyCode))
            {
                return;
            }

            Host.KeyPressed(info);
            KeyPress?.Invoke(info);
        }
Пример #17
0
 /// <summary>Invoked when the user presses a key.</summary>
 /// <param name="evnt">The event data.</param>
 /// <returns>True if event has handled.</returns>
 protected override bool OnKeyPressEvent(EventKey evnt)
 {
     try
     {
         KeyPress?.Invoke(this, evnt);
     }
     catch (Exception ex)
     {
         MainView.MasterView.ShowError(ex);
     }
     return(true);
 }
Пример #18
0
 /// <summary>Invoked when the user presses a key.</summary>
 /// <param name="evnt">The event data.</param>
 /// <returns>True if event has handled.</returns>
 public bool OnKeyPressEvent(SheetEventKey evnt)
 {
     try
     {
         KeyPress?.Invoke(this, evnt);
     }
     catch (Exception ex)
     {
         MainView.MasterView.ShowError(ex);
     }
     return(true);
 }
 protected override void OnTextInput(global::Avalonia.Input.TextInputEventArgs e)
 {
     base.OnTextInput(e);
     if (e.Text == null)
     {
         return;
     }
     foreach (var c in e.Text)
     {
         KeyPress?.Invoke(new TextInputEventArgs(c));
     }
 }
Пример #20
0
        private void OnKeyPress(Keys key)
        {
            if (KeyModifiers.ModifierKeys.Contains(key))
            {
                return;
            }

            var str = KeyString(key);

            lastKeyPress = currentTime;
            KeyPress?.Invoke(this, new KeyPressEventArgs(key, str, modifiers));
        }
Пример #21
0
        private void Callback()
        {
            for (var i = 0; i < 255; i++)
            {
                int key = Native.GetAsyncKeyState(i);

                if (key == UP || key == DOWN)
                {
                    KeyPress?.Invoke((Keys)i);
                    break;
                }
            }
        }
Пример #22
0
 public void Start()
 {
     Console.WriteLine("Running!");
     while (true)
     {
         char charKey = Console.ReadKey(true).KeyChar;
         //if (KeyClick != null)
         //{
         //    KeyClick(charKey);
         //}
         KeyClick?.Invoke(charKey);
     }
 }
Пример #23
0
        private bool Handle(KeyState state, KeyboardState data)
        {
            Keys key     = data.Key;
            char?keyChar = null;

            if (User32.IsKeyPressed(Keys.ControlKey))
            {
                key |= Keys.Control;
            }
            if (User32.IsKeyPressed(Keys.AltKey))
            {
                key |= Keys.Alt;
            }
            if (User32.IsKeyPressed(Keys.ShiftKey) is { } shift&& shift)
            {
                key |= Keys.Shift;
            }
            bool capsLock = User32.IsKeyToggled(Keys.CapsLock);

            byte[]        keyboardState = new byte[256];
            StringBuilder chars         = new StringBuilder(8);

            User32.GetKeyboardState(keyboardState);
            if (User32.ToAscii(data.Key, data.ScanCode, keyboardState, chars, data.Flags) == 1)
            {
                keyChar = shift ^ capsLock?char.ToUpper(chars[0]) : chars[0];
            }

            IKeyboardEventArgs e = new KeyboardEventArgs(key, state, keyChar, data.DateTime);

            InvokeOnEvent(this, e);

            switch (state)
            {
            case KeyState.Down:
            case KeyState.SysDown:
                KeyDown?.Invoke(this, e);
                KeyPress?.Invoke(this, e);
                break;

            case KeyState.Up:
            case KeyState.SysUp:
                KeyUp?.Invoke(this, e);
                break;

            default:
                break;
            }

            return(e.DefaultPrevented);
        }
Пример #24
0
        } // Update

        #endregion

        #region Update Keyboard

        /// <summary>
        /// Update keyboard.
        /// </summary>
        private void UpdateKeys()
        {

            KeyEventArgs e = new KeyEventArgs { Caps = (((ushort) GetKeyState(0x14)) & 0xffff) != 0 };

            foreach (Keys key in Keyboard.State.GetPressedKeys())
            {
                if      (key == Keys.LeftAlt     || key == Keys.RightAlt)     e.Alt = true;
                else if (key == Keys.LeftShift   || key == Keys.RightShift)   e.Shift = true;
                else if (key == Keys.LeftControl || key == Keys.RightControl) e.Control = true;
            }

            foreach (InputKey key in keys)
            {
                if (key.Key == Keys.LeftAlt     || key.Key == Keys.RightAlt   ||
                    key.Key == Keys.LeftShift   || key.Key == Keys.RightShift ||
                    key.Key == Keys.LeftControl || key.Key == Keys.RightControl)
                {
                    continue;
                }

                bool pressed = Keyboard.State.IsKeyDown(key.Key);

                double frameTimeInMilliseconds = Time.GameDeltaTime * 1000; // From seconds to milliseconds.
                if (pressed) key.Countdown -= frameTimeInMilliseconds;

                if ((pressed) && (!key.Pressed))
                {
                    key.Pressed = true;
                    e.Key = key.Key;

                    if (KeyDown  != null) KeyDown.Invoke(this, e);
                    if (KeyPress != null) KeyPress.Invoke(this, e);
                }
                else if ((!pressed) && (key.Pressed))
                {
                    key.Pressed = false;
                    key.Countdown = repeatDelay;
                    e.Key = key.Key;

                    if (KeyUp != null) KeyUp.Invoke(this, e);
                }
                else if (key.Pressed && key.Countdown < 0)
                {
                    key.Countdown = repeatRate;
                    e.Key = key.Key;

                    if (KeyPress != null) KeyPress.Invoke(this, e);
                }
            }
        } // UpdateKeys
Пример #25
0
        private void KeyInputRequest()
        {
            //ConsoleKeyInfo key;

            //do
            //{
            Console.WriteLine(" Запрос ввода:");
            key = Console.ReadKey();

            //OnKeyPress(key);    // HACK KeyPress?.Invoke(key);
            KeyPress?.Invoke(key);

            //} while (key.Key != ConsoleKey.Escape);
        }
Пример #26
0
        void OnKeyPress(jQueryKeyboardEvent e)
        {
            KeyPress?.Invoke(e);

            if (AllowOnlyDecimalInputs)
            {
                DisableNonDecimalInputs(e);
                return;
            }

            if (AllowOnlyNumericInputs)
            {
                DisableNonNumericValues(e);
            }
        }
Пример #27
0
        private void keyboardHook_Callback(int nCode, IntPtr wParam, IntPtr lParam, ref bool handled)
        {
            KeyboardHookStruct keyboardHookStruct = (KeyboardHookStruct)Marshal.PtrToStructure(lParam, typeof(KeyboardHookStruct));

            //raise KeyDown
            if (KeyDown != null && ((int)wParam == WM_KEYDOWN || (int)wParam == WM_SYSKEYDOWN))
            {
                Keys         keyData = (Keys)keyboardHookStruct.VirtualKeyCode;
                KeyEventArgs e       = new KeyEventArgs(keyData);
                KeyDown.Invoke(null, e);
                handled = e.Handled;
            }

            // raise KeyPress
            if (KeyPress != null && (int)wParam == WM_KEYDOWN)
            {
                bool isDownShift    = (GetKeyState(VK_SHIFT) & 0x80) != 0;
                bool isDownCapslock = GetKeyState(VK_CAPITAL) != 0;

                byte[] keyState = new byte[256];
                GetKeyboardState(keyState);
                byte[] inBuffer = new byte[2];
                if (ToAscii(keyboardHookStruct.VirtualKeyCode,
                            keyboardHookStruct.ScanCode,
                            keyState,
                            inBuffer,
                            keyboardHookStruct.Flags) == 1)
                {
                    char key = (char)inBuffer[0];
                    if ((isDownCapslock ^ isDownShift) && Char.IsLetter(key))
                    {
                        key = Char.ToUpper(key);
                    }
                    KeyPressEventArgs e = new KeyPressEventArgs(key);
                    KeyPress.Invoke(null, e);
                    handled = handled || e.Handled;
                }
            }

            // raise KeyUp
            if (KeyUp != null && ((int)wParam == WM_KEYUP || (int)wParam == WM_SYSKEYUP))
            {
                Keys         keyData = (Keys)keyboardHookStruct.VirtualKeyCode;
                KeyEventArgs e       = new KeyEventArgs(keyData);
                KeyUp.Invoke(null, e);
                handled = handled || e.Handled;
            }
        }
Пример #28
0
    // Update is called once per frame
    void Update()
    {
        if (GamePauseControl.IsPaused)
        {
            return;
        }

        _cardinalInputs.x = Mathf.Round(Input.GetAxisRaw("Horizontal"));
        _cardinalInputs.y = Mathf.Round(Input.GetAxisRaw("Vertical"));
        InpDirection.Invoke(_cardinalInputs);

        InpJump.Invoke(Input.GetKey(jumpKey));
        InpShoot.Invoke(Input.GetKeyDown(shootKey));
        InpThunder.Invoke(Input.GetKeyDown(thunderKey));
        InpBloodAmmo.Invoke(Input.GetKeyDown(bloodAmmoKey));
    }
Пример #29
0
        protected override HookResult HookProc(int code, int wParam, ref KeyboardHookData lParam)
        {
            Keys key = (Keys)lParam.vkCode;

            //Key Press Event
            KeyEventArgs keyEvent = new KeyEventArgs(key);

            if (wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN)
            {
                KeyPress?.Invoke(keyEvent);
                if (ManageHook != null)
                {
                    return(ManageHook.Invoke(key));
                }
            }
            return(HookResult.Release);
        }
Пример #30
0
        public bool PreFilterMessage(ref Message m)
        {
            var     key        = (Keys)m.WParam;
            Boolean keyPressed = false;

            if (m.Msg == WM_KEYDOWN)
            {
                return(KeysDictionary[key] = true);
            }
            else if (m.Msg == WM_KEYUP)
            {
                return(!(KeysDictionary[key] = false));
            }
            else if (m.Msg == WM_LBUTTONDOWN)
            {
                key = Keys.LButton;
                return(KeysDictionary[key] = true);
            }
            else if (m.Msg == WM_LBUTTONUP)
            {
                key = Keys.LButton;
                return(!(KeysDictionary[key] = false));
            }
            else if (m.Msg == WM_RBUTTONDOWN)
            {
                key = Keys.RButton;
                return(KeysDictionary[key] = true);
            }
            else if (m.Msg == WM_RBUTTONUP)
            {
                key = Keys.RButton;
                return(!(KeysDictionary[key] = false));
            }
            if (keyPressed)
            {
                KeyPress?.Invoke(this, new KeyEventArgs(key));
            }
            else
            {
                KeyUp?.Invoke(this, new KeyEventArgs(key));
            }
            return(false);
        }