diff --git a/src/UnoKeyboard/Controls/KeyControl.cs b/src/UnoKeyboard/Controls/KeyControl.cs index 44294d8..d51ddea 100644 --- a/src/UnoKeyboard/Controls/KeyControl.cs +++ b/src/UnoKeyboard/Controls/KeyControl.cs @@ -71,20 +71,11 @@ public KeyControl(KeyboardControl keyboard) Mode = BindingMode.OneWay, }); - this.Tapped += (s, e) => + this.PointerReleased += (s, e) => { -#if HAS_UNO - Focus(FocusState.Programmatic); -#endif + e.Handled = true; KeyPressed?.Invoke(this, new KeyEventArgs(Key, IsShiftActive)); - -#if !HAS_UNO - if (Keyboard.TextControl != null) - { - Keyboard.TextControl.Focus(FocusState.Programmatic); - } -#endif }; } diff --git a/src/UnoKeyboard/Controls/KeyboardControl.Events.cs b/src/UnoKeyboard/Controls/KeyboardControl.Events.cs index cea4716..090ef15 100644 --- a/src/UnoKeyboard/Controls/KeyboardControl.Events.cs +++ b/src/UnoKeyboard/Controls/KeyboardControl.Events.cs @@ -79,7 +79,7 @@ public void OnKeyClicked(object? sender, KeyEventArgs e) TextControl.Text = TextControl.Text.Insert(currentPos, " "); TextControl.SelectionStart = currentPos + 1; break; - + case KeyType.Text: currentPos = TextControl.SelectionStart; TextControl.Text = TextControl.Text.Insert(currentPos, IsShiftActive ? e.Key.VKey.UValue : e.Key.VKey.LValue); @@ -100,18 +100,11 @@ public void OnKeyClicked(object? sender, KeyEventArgs e) private void OnLosingFocus(object? sender, LosingFocusEventArgs args) { // THAT DOESN'T WORK FOR WINDOWS -#if HAS_UNO // When a KeyControl gets the focus, the event has to be canceled so the TextBox doesn't lose the focus. - if ((args.NewFocusedElement is null || args.NewFocusedElement is KeyControl) - && args.OldFocusedElement is TextBox) - { - args.Cancel = true; - return; - } -#endif - if (Visibility == Visibility.Visible) + if (args.OldFocusedElement == TextControl && Visibility == Visibility.Visible) { - DispatcherQueue?.TryEnqueue(() => Visibility = Visibility.Collapsed); + TextControl = null; + Visibility = Visibility.Collapsed; } } @@ -119,40 +112,38 @@ private void OnGettingFocus(object? sender, GettingFocusEventArgs args) { if (args.NewFocusedElement is TextBox textBox) { - DispatcherQueue?.TryEnqueue(() => - { - // Gets the keyboard type from the attached property. - var kbrIdProp = textBox.GetValue(McWindowEx.KeyboardIdProperty); - if (kbrIdProp is string keyboardId) + // Gets the keyboard type from the attached property. + var kbrIdProp = textBox.GetValue(McWindowEx.KeyboardIdProperty); + + if (kbrIdProp is string keyboardId) + { + if (keyboardId == "None") { - if (keyboardId == "None") - { - if (Keyboard is null || Keyboard.Id != Keyboards.Keyboard.First().Key) - { - _currentPage = 0; - Keyboard = Keyboards.Keyboard.First().Value; - } - else - { - CurrentPage = 0; - } - } - else if (Keyboard is null || Keyboard.Id != keyboardId) + if (Keyboard is null || Keyboard.Id != Keyboards.Keyboard.First().Key) { _currentPage = 0; - Keyboard = Keyboards.Keyboard[keyboardId]; + Keyboard = Keyboards.Keyboard.First().Value; } else { CurrentPage = 0; } } + else if (Keyboard is null || Keyboard.Id != keyboardId) + { + _currentPage = 0; + Keyboard = Keyboards.Keyboard[keyboardId]; + } + else + { + CurrentPage = 0; + } + } - TextControl = textBox; + TextControl = textBox; - Visibility = Visibility.Visible; - }); + Visibility = Visibility.Visible; } } }