Exemplo n.º 1
0
        protected void ExecuteKeyPress(KeyEvent evt)
        {
            Key key = evt.Key;

            if (KeyPreview != null)
            {
                KeyPreview(ref key);
            }
            if (key == Key.None)
            {
                return;
            }
            // Try key bindings...
            KeyAction keyAction;

            lock (_syncObj)
                if (!_keyBindings.TryGetValue(key, out keyAction))
                {
                    keyAction = null;
                }
            if (keyAction != null)
            {
                keyAction.Action();
            }
            else
            {
                KeyPressedHandler dlgt = KeyPressed;
                if (dlgt != null)
                {
                    dlgt(ref key);
                }
            }
        }
Exemplo n.º 2
0
 public void KeyPressed(VirtualKey keyCode, int repeatCount)
 {
     KeyPressedHandler?.Invoke(new KeyPressedEventArgs
     {
         KeyCode   = keyCode,
         Modifiers = new KeyModifiers
         {
             Alt     = User32Methods.GetKeyState(VirtualKey.MENU).IsPressed,
             Control = User32Methods.GetKeyState(VirtualKey.CONTROL).IsPressed,
             Shift   = User32Methods.GetKeyState(VirtualKey.SHIFT).IsPressed
         },
         Repeat = repeatCount != 0
     });
 }
Exemplo n.º 3
0
        protected void ExecuteKeyPress(KeyEvent evt)
        {
            Key key = evt.Key;

            if (key == null)
            {
                return;
            }

            if (KeyPreview != null)
            {
                KeyPreview(ref key);
            }

            if (key == null)
            {
                return;
            }

            var routedKeyEventArgs = new KeyEventArgs(Environment.TickCount, key);

            // invoke routed KeyPress event
            // if event is already handled, we set Handled to true. By this only handlers registered with handledEventsToo = true will be invoked
            if (key == Key.None)
            {
                routedKeyEventArgs.Handled = true;
            }
            ExecuteRoutedInputEvent(new RoutedInputEvent(routedKeyEventArgs, UIElement.PreviewKeyPressEvent));
            if (routedKeyEventArgs.Handled)
            {
                key = Key.None;
            }

            if (key != Key.None)
            {
                // Try key bindings...
                KeyAction keyAction;
                lock (_syncObj)
                    if (!_keyBindings.TryGetValue(key, out keyAction))
                    {
                        keyAction = null;
                    }
                if (keyAction != null)
                {
                    keyAction.Action();
                }
            }

            // invoke routed KeyPress event
            // if event is already handled, we set Handled to true. By this only handlers registered with handledEventsToo = true will be invoked
            // it is important to invoke routed KeyPressed event before 'internal' OnKeyPressed,
            // b/c internal OnKeyPress makes focus handling in Screen as final action if event was not handled
            if (key == Key.None)
            {
                routedKeyEventArgs.Handled = true;
            }
            ExecuteRoutedInputEvent(new RoutedInputEvent(routedKeyEventArgs, UIElement.KeyPressEvent));
            if (routedKeyEventArgs.Handled)
            {
                key = Key.None;
            }

            if (key != Key.None)
            {
                KeyPressedHandler dlgt = KeyPressed;
                if (dlgt != null)
                {
                    dlgt(ref key);
                }
            }
        }