コード例 #1
0
        /// <summary>
        /// Run the KeyInput directly in the Wpf control
        /// </summary>
        private void RunInWpf(KeyInput keyInput)
        {
            Castle.DynamicProxy.Generators.AttributesToAvoidReplicating.Add(typeof(UIPermissionAttribute));
            var presentationSource = _factory.Create <PresentationSource>();

            // Normalize upper case letters here to lower and add the shift key modifier if
            // necessary
            if (Char.IsUpper(keyInput.Char))
            {
                var lowerKeyInput = KeyInputUtil.CharToKeyInput(Char.ToLower(keyInput.Char));
                keyInput = KeyInputUtil.ChangeKeyModifiers(lowerKeyInput, keyInput.KeyModifiers | KeyModifiers.Shift);
            }

            Key key;

            if (!KeyUtil.TryConvertToKeyOnly(keyInput.Key, out key))
            {
                throw new Exception("Couldn't get the WPF key for the given KeyInput");
            }

            // Update the KeyModifiers while this is being processed by our key processor
            try
            {
                _defaultKeyboardDevice.DownKeyModifiers = keyInput.KeyModifiers;

                // First raise the KeyDown event
                var keyDownEventArgs = new KeyEventArgs(
                    _defaultKeyboardDevice,
                    presentationSource.Object,
                    0,
                    key);
                keyDownEventArgs.RoutedEvent = UIElement.KeyDownEvent;
                _defaultInputController.HandleKeyDown(this, keyDownEventArgs);

                // If the event is handled then return
                if (keyDownEventArgs.Handled)
                {
                    return;
                }

                // Now raise the TextInput event
                var textInputEventArgs = new TextCompositionEventArgs(
                    _defaultKeyboardDevice,
                    new TextComposition(InputManager.Current, _wpfTextView.VisualElement, keyInput.Char.ToString()));
                textInputEventArgs.RoutedEvent = UIElement.TextInputEvent;
                _defaultInputController.HandleTextInput(this, textInputEventArgs);

                var keyUpEventArgs = new KeyEventArgs(
                    _defaultKeyboardDevice,
                    presentationSource.Object,
                    0,
                    key);
                keyUpEventArgs.RoutedEvent = UIElement.KeyUpEvent;
                _defaultInputController.HandleKeyUp(this, keyUpEventArgs);
            }
            finally
            {
                _defaultKeyboardDevice.DownKeyModifiers = KeyModifiers.None;
            }
        }
コード例 #2
0
        /// <summary>
        /// Run the KeyInput directly in the Wpf control
        /// </summary>
        private void Run(string text, Key key, ModifierKeys modifierKeys)
        {
            // First raise the KeyDown event
            var keyDownEventArgs = new KeyEventArgs(
                _defaultKeyboardDevice,
                _presentationSource.Object,
                0,
                key);

            keyDownEventArgs.RoutedEvent = UIElement.KeyDownEvent;
            _defaultInputController.HandleKeyDown(this, keyDownEventArgs);

            // If the event is handled then return
            if (keyDownEventArgs.Handled)
            {
                return;
            }

            // Now raise the TextInput event
            var textInputEventArgs = new TextCompositionEventArgs(
                _defaultKeyboardDevice,
                CreateTextComposition(text));

            textInputEventArgs.RoutedEvent = UIElement.TextInputEvent;
            _defaultInputController.HandleTextInput(this, textInputEventArgs);

            var keyUpEventArgs = new KeyEventArgs(
                _defaultKeyboardDevice,
                _presentationSource.Object,
                0,
                key);

            keyUpEventArgs.RoutedEvent = UIElement.KeyUpEvent;
            _defaultInputController.HandleKeyUp(this, keyUpEventArgs);
        }
コード例 #3
0
        /// <summary>
        /// Run the KeyInput directly in the Wpf control
        /// </summary>
        private void Run(string text, KeyInput keyInput, Key key, ModifierKeys modifierKeys)
        {
            if (!RunDown(keyInput, key, modifierKeys))
            {
                // If the down event wasn't handled then we should proceed to actually providing
                // textual composition
                var textInputEventArgs = new TextCompositionEventArgs(
                    _defaultKeyboardDevice,
                    CreateTextComposition(text));
                textInputEventArgs.RoutedEvent = UIElement.TextInputEvent;
                _defaultInputController.HandleTextInput(this, textInputEventArgs);
            }

            // The key up code is processed even if the down or text composition is handled by
            // the calling code.  It's an independent event
            RunUp(keyInput, key, modifierKeys);
        }