0
votes

Platform: C# WPF

Environment: Visual Studio 2013

Question # 1: I want to show third party on screen keyboard on mouse left button down on PasswordBox control of C# WPF. I used the following code:

private void PasswordBox_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
    System.Diagnostics.Process.Start("D:\\CCOnScreenKeyboard.exe"); 
}

But it does not start on screen key board. Instead it triggers on MouseDoubleClick and GotFocus events.

Question # 2:

I want to Hide on screen keyboard when mouse click outside the PasswordBox and Show again on mouse left button down inside box.

Question # 3:

I want to show keyboard on single click instead of mouse double click

2
You might want to consider starting the process when your app starts and then only change the visibility of the OnscreenKeyboard form when needed. This might be less buggy.Maxter
Yes @ Maxter and also on mouse single click instead of double clickshakeel ahmad

2 Answers

0
votes

I belive the best way to do this will be through using the Focus events, as you only want the keyboard when you're interacting with the PasswordBox, and for it to go once you have stopped interacting.

private void PasswordBox_GotFocus(object sender, RoutedEventArgs e) => 
    Process.Start("D:\\CCOnScreenKeyboard.exe");

private void PasswordBox_LostFocus(object sender, RoutedEventArgs e)
{
    foreach (var process in Process.GetProcessesByName("CCOnScreenKeyboard"))
        process.Kill();
}
0
votes

You could handle the PreviewMouseLeftButtonDown event for the parent window. Something like this:

bool isVisible = false;
PreviewMouseLeftButtonDown += (ss, ee) => 
{
    if (!passwordBox.IsMouseOver && isVisible)
    {
        System.Diagnostics.Process.GetProcessesByName("CCOnScreenKeyboard")?.FirstOrDefault()?.Kill();
    }
    else if (!isVisible)
    {
        System.Diagnostics.Process.Start("D:\\CCOnScreenKeyboard.exe");
        isVisible = true;

    }
};