From d6d15f4a86ebccb10c962e9c1dbdc71b090f4138 Mon Sep 17 00:00:00 2001 From: MattiasEppler Date: Mon, 13 Feb 2023 10:23:11 +0100 Subject: [PATCH 1/2] Add buttons to wpf sample to show and hide keyboard --- WpfSample/MainWindow.xaml | 2 ++ WpfSample/MainWindow.xaml.cs | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/WpfSample/MainWindow.xaml b/WpfSample/MainWindow.xaml index 1c70b52..345dd99 100644 --- a/WpfSample/MainWindow.xaml +++ b/WpfSample/MainWindow.xaml @@ -25,6 +25,8 @@ + + diff --git a/WpfSample/MainWindow.xaml.cs b/WpfSample/MainWindow.xaml.cs index 49e98f0..b058092 100644 --- a/WpfSample/MainWindow.xaml.cs +++ b/WpfSample/MainWindow.xaml.cs @@ -77,5 +77,15 @@ private void MenuItem_Click(object sender, RoutedEventArgs e) wnd.Owner = this; wnd.Show(); } + + private void Show(object sender, RoutedEventArgs e) + { + OnScreenKeyboard.Show(); + } + + private void Hide(object sender, RoutedEventArgs e) + { + OnScreenKeyboard.Close(); + } } } From daa777265cf1a5c0cc28544154bd6cd08fbe55c5 Mon Sep 17 00:00:00 2001 From: MattiasEppler Date: Mon, 13 Feb 2023 10:43:55 +0100 Subject: [PATCH 2/2] Bugfix: StartTabtip and ask immediately if IsOpend() leads to a timing problem. Change: name the same functions the same. ToggleByCom() instead of ShowByCom --- Osklib/ComOnScreenKeyboardController.cs | 1 + Osklib/NewWindows10OnScreenKeyboardController.cs | 7 ++++--- Osklib/Windows10OnScreenKeyboardController.cs | 8 ++++---- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Osklib/ComOnScreenKeyboardController.cs b/Osklib/ComOnScreenKeyboardController.cs index 7664cfb..61f1e81 100644 --- a/Osklib/ComOnScreenKeyboardController.cs +++ b/Osklib/ComOnScreenKeyboardController.cs @@ -103,6 +103,7 @@ public override void Show() { StartTabTip(); // on some devices starting TabTip don't show keyboard, on some does ¯\_(ツ)_/¯ + Thread.Sleep(1000); if (!IsOpened()) { ToggleByCom(); diff --git a/Osklib/NewWindows10OnScreenKeyboardController.cs b/Osklib/NewWindows10OnScreenKeyboardController.cs index a60a6b1..b2bbb21 100644 --- a/Osklib/NewWindows10OnScreenKeyboardController.cs +++ b/Osklib/NewWindows10OnScreenKeyboardController.cs @@ -82,7 +82,7 @@ private static void StartTabTip() } } - private static void ShowByCom() + private static void ToggleByCom() { try { @@ -105,16 +105,17 @@ public override void Show() { if (!IsOpened()) { - ShowByCom(); + ToggleByCom(); } } else { StartTabTip(); // on some devices starting TabTip don't show keyboard, on some does ¯\_(ツ)_/¯ + Thread.Sleep(1000); if (!IsOpened()) { - ShowByCom(); + ToggleByCom(); } } } diff --git a/Osklib/Windows10OnScreenKeyboardController.cs b/Osklib/Windows10OnScreenKeyboardController.cs index 0765046..9dbf390 100644 --- a/Osklib/Windows10OnScreenKeyboardController.cs +++ b/Osklib/Windows10OnScreenKeyboardController.cs @@ -49,13 +49,12 @@ private static void StartTabTip() } } - private static void ShowByCom() + private static void ToggleByCom() { ITipInvocation instance = null; try { instance = (ITipInvocation)Activator.CreateInstance(ComTypes.TipInvocationType); - var window = NativeMethods.GetDesktopWindow(); instance.Toggle(NativeMethods.GetDesktopWindow()); } finally @@ -75,16 +74,17 @@ public override void Show() //Console.WriteLine( "Style {0:X8}", style ); if (!NativeMethods.IsWin10OnScreenKeyboardVisible()) { - ShowByCom(); + ToggleByCom(); } } else { StartTabTip(); // on some devices starting TabTip don't show keyboard, on some does ¯\_(ツ)_/¯ + Thread.Sleep(1000); if (!IsOpened()) { - ShowByCom(); + ToggleByCom(); } } }