private static void PreProcessKeyboardInput(object sender, PreProcessInputEventArgs e)
        {
            if (e.Input.Device == Keyboard.PrimaryDevice)
            {
                KeyEventArgs keyEventArgs = e.Input as KeyEventArgs;

                if (keyEventArgs != null)
                {
                    string text = keyEventArgs.KeyboardDevice.KeyToString(keyEventArgs.Key);

                    if (text != string.Empty && !char.IsControl(text[0]))
                    {
                        TextComposition composition = new TextComposition(
                            InputManager.Current,
                            keyEventArgs.Device.Target,
                            text);

                        TextCompositionEventArgs ev = new TextCompositionEventArgs(
                            keyEventArgs.Device,
                            composition);
                        ev.RoutedEvent = TextInputEvent;

                        InputManager.Current.ProcessInput(ev);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public static TextComposition CreateTextComposition(this FrameworkElement frameworkElement, string text, InputManager inputManager = null)
        {
            inputManager = inputManager ?? InputManager.Current;
            var textComposition = new TextComposition(inputManager, frameworkElement, text);

            if (text.Length == 1)
            {
                var c = text[0];
                if (Char.IsControl(c))
                {
                    var type   = typeof(TextComposition);
                    var method = type.GetMethod("MakeControl", BindingFlags.Instance | BindingFlags.NonPublic);
                    method.Invoke(textComposition, new object[] { });
                    Assert.True(String.IsNullOrEmpty(textComposition.Text));
                    Assert.Equal(text, textComposition.ControlText);
                }
                else if (0 != (c & 0x80))
                {
                    var type   = typeof(TextComposition);
                    var method = type.GetMethod("MakeSystem", BindingFlags.Instance | BindingFlags.NonPublic);
                    method.Invoke(textComposition, new object[] { });
                    Assert.True(String.IsNullOrEmpty(textComposition.Text));
                    Assert.Equal(text, textComposition.SystemText);
                }
            }

            return(textComposition);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Performs text input.
        /// This raises the <see cref="TextEntering"/> event, replaces the selection with the text,
        /// and then raises the <see cref="TextEntered"/> event.
        /// </summary>
        public void PerformTextInput(string text)
        {
            TextComposition          textComposition = new TextComposition(InputManager.Current, this, text);
            TextCompositionEventArgs e = new TextCompositionEventArgs(Keyboard.PrimaryDevice, textComposition);

            e.RoutedEvent = TextInputEvent;
            PerformTextInput(e);
        }
        private void TbRaiseEvent(TextBox tb, InputDevice inDevice, string txtToSend)
        {
            TextComposition          tc   = new TextComposition(InputManager.Current, tb, txtToSend);
            TextCompositionEventArgs args = new TextCompositionEventArgs(inDevice, tc);

            args.RoutedEvent = TextCompositionManager.TextInputEvent;
            tb.RaiseEvent(args);
        }
Ejemplo n.º 5
0
        private void SelectCharactorButtonOnClick(object sender, RoutedEventArgs e)
        {
            var button = sender as Button;
            var text   = button.Content as string;

            if (text != null)
            {
                var composition = new TextComposition(InputManager.Current, this.Output, text);
                TextCompositionManager.StartComposition(composition);
                this.Clear();
            }
        }
Ejemplo n.º 6
0
        internal static void OnTextCompositionEnded(object sender)
        {
            if (TextComposition != null)
            {
                TextComposition.Invoke(sender, new IMETextCompositionEventArgs(IMEString.Empty, 0));
            }

            if (TextCompositionCallback != null)
            {
                TextCompositionCallback(IMEString.Empty, 0, null, 0, 0, 0);
            }
        }
Ejemplo n.º 7
0
        private void OnTextBoxKeyDown(object sender, KeyEventArgs eventArgs)
        {
            // Translate the numpad decimal key to the correct decimal separator.
            if (eventArgs.Key == Key.Decimal)
            {
                eventArgs.Handled = true;

                var cultureInfo     = _textBox.Language.GetSpecificCulture();
                var textComposition = new TextComposition(InputManager.Current, _textBox, cultureInfo.NumberFormat.NumberDecimalSeparator);
                TextCompositionManager.StartComposition(textComposition);
            }
        }
        /// <summary>
        /// Sends the input.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="text">The text.</param>
        public void SendInput(UIElement element, string text)
        {
            InputManager             inputManager = InputManager.Current;
            InputDevice              inputDevice  = inputManager.PrimaryKeyboardDevice;
            TextComposition          composition  = new TextComposition(inputManager, element, text);
            TextCompositionEventArgs args         = new TextCompositionEventArgs(inputDevice, composition);

            args.RoutedEvent = PreviewTextInputEvent;
            element.RaiseEvent(args);
            args.RoutedEvent = TextInputEvent;
            element.RaiseEvent(args);
        }
Ejemplo n.º 9
0
        private TextCompositionEventArgs FirePreviewTextInputEvent(string inputText)
        {
            var textComposition          = new TextComposition(InputManager.Current, Keyboard.FocusedElement, inputText);
            var textCompositionEventArgs =
                new TextCompositionEventArgs(InputManager.Current.PrimaryKeyboardDevice, textComposition)
            {
                RoutedEvent = TextCompositionManager.PreviewTextInputEvent
            };

            _numberTextBox.RaiseEvent(textCompositionEventArgs);

            return(textCompositionEventArgs);
        }
Ejemplo n.º 10
0
        public static void WriteText(this TextBox textBox, string text, bool overwrite = true)
        {
            if (overwrite)
            {
                textBox.SelectAll();
            }
            var composition = new TextComposition(InputManager.Current, textBox, text);

            TextCompositionManager.StartComposition(composition);
            if (text == "")
            {
                textBox.Text = "";
            }
        }
Ejemplo n.º 11
0
        public static void RaiseTextInputEvent(UIElement element, string text)
        {
            if (element == null)
            {
                return;
            }

            InputManager             inputManager = InputManager.Current;
            InputDevice              inputDevice  = inputManager.PrimaryKeyboardDevice;
            TextComposition          composition  = new TextComposition(inputManager, element, text);
            TextCompositionEventArgs args         = new TextCompositionEventArgs(inputDevice, composition);

            args.RoutedEvent = UIElement.PreviewTextInputEvent;
            element.RaiseEvent(args);
            args.RoutedEvent = UIElement.TextInputEvent;
            element.RaiseEvent(args);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Sends the decimal separator to the focused element.
        /// </summary>
        /// <param name="separator">The separator.</param>
        private static void SendDecimalSeparator(string separator)
        {
            // Send the specified separator text to the focused element.
            // Send it using TextCompositionManager.PreviewTextInputEvent first and if the event
            // is not marked as Handled, raise TextCompositionManager.TextInputEvent.
            var composition = new TextComposition(InputManager.Current, Keyboard.FocusedElement, separator);
            var args        = new TextCompositionEventArgs(InputManager.Current.PrimaryKeyboardDevice, composition)
            {
                RoutedEvent = TextCompositionManager.PreviewTextInputEvent
            };

            Keyboard.FocusedElement.RaiseEvent(args);
            if (!args.Handled)
            {
                args.RoutedEvent = TextCompositionManager.TextInputEvent;
                Keyboard.FocusedElement.RaiseEvent(args);
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Simulate the given KeyInput being sent to the given UIElement
        /// </summary>
        public void SendKeyStroke(UIElement target, KeyInput keyInput)
        {
            Key          key;
            ModifierKeys modKeys;

            if (!TryGetKeyForKeyInput(keyInput, out key, out modKeys))
            {
                throw new Exception();
            }

            ModifierKeysImpl = modKeys;
            try
            {
                // First step is preview key down
                var keyEventArgs = new KeyEventArgs(
                    this,
                    new MockPresentationSource(),
                    0,
                    key);

                if (!RaiseEvents(target, keyEventArgs, Keyboard.PreviewKeyDownEvent, Keyboard.KeyDownEvent))
                {
                    var raiseUp = true;
                    if (char.IsLetterOrDigit(keyInput.Char))
                    {
                        var textComposition          = new TextComposition(InputManager.Current, target, keyInput.Char.ToString());
                        var textCompositionEventArgs = new TextCompositionEventArgs(this, textComposition);
                        raiseUp = !RaiseEvents(target, textCompositionEventArgs, TextCompositionManager.TextInputEvent);
                    }

                    if (raiseUp)
                    {
                        RaiseEvents(target, keyEventArgs, Keyboard.PreviewKeyUpEvent, Keyboard.KeyUpEvent);
                    }
                }
            }
            finally
            {
                ModifierKeysImpl = ModifierKeys.None;
            }
        }
Ejemplo n.º 14
0
        private void textEditor_TextArea_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Space && (Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control)
            {
                var offset = _editor.CaretOffset;
                if (offset > 0)
                {
                    char c = _editor.Text[offset - 1];

                    TextComposition tc   = new TextComposition(null, null, c.ToString(CultureInfo.InvariantCulture));
                    var             tcea = new TextCompositionEventArgs(null, tc);

                    bool foundProposal = completeBasedOnTextEntered(tcea);
                    if (!foundProposal)
                    {
                        completeOnCtrlSpace();
                    }
                }
                e.Handled = true;
            }
        }
Ejemplo n.º 15
0
        // On text composition update.
        internal static void OnTextComposition(object sender, IMEString compositionText, int cursorPos)
        {
            if (compositionText.Count == 0) // Crash guard
            {
                cursorPos = 0;
            }

            if (cursorPos > compositionText.Count)  // Another crash guard
            {
                cursorPos = compositionText.Count;
            }

            if (TextComposition != null)
            {
                TextComposition.Invoke(sender,
                                       new IMETextCompositionEventArgs(compositionText, cursorPos, CandidateList, CandidatePageStart, CandidatePageSize, CandidateSelection));
            }

            if (TextCompositionCallback != null)
            {
                TextCompositionCallback(compositionText, cursorPos, CandidateList, CandidatePageStart, CandidatePageSize, CandidateSelection);
            }
        }
Ejemplo n.º 16
0
 public TextCompositionEventArgs(InputDevice inputDevice, TextComposition composition)
     : base(inputDevice, 0)
 {
     this.Text = composition.Text;
 }
 public TextCompositionEventArgs(InputDevice inputDevice, TextComposition composition)
     : base(inputDevice, 0)
 {
     this.Text = composition.Text;
 }