Mouse left click and On-Screen-Keyboard

501 views Asked by At

I'm writing application which is using kinect for windows v2 to display and control mouse by left hand. I wrote method that invoke mouse left click and everything works great.

I have problem with one action. If I launch On-Screen-Keyboard, my mentioned click method is not working. But outside the OSK windows it's still works perfect. Do you know what's going on ? Here's some of my code.

public static void PerformLeftClick()
{
    INPUT mouseDownInput = new INPUT();
    mouseDownInput.type = SendInputEventType.InputMouse;
    mouseDownInput.mkhi.mi.dwFlags = MouseEventFlags.MOUSEEVENTF_LEFTDOWN;
    SendInput(1, ref mouseDownInput, Marshal.SizeOf(new INPUT()));

    INPUT mouseUpInput = new INPUT();
    mouseUpInput.type = SendInputEventType.InputMouse;
    mouseUpInput.mkhi.mi.dwFlags = MouseEventFlags.MOUSEEVENTF_LEFTUP;
    SendInput(1, ref mouseUpInput, Marshal.SizeOf(new INPUT()));
}

private void ShowOnScreenKeyboard(object sender, RoutedEventArgs e)
{
    var keyBoardProccess = Process.GetProcessesByName("osk");
    if (keyBoardProccess.Length == 0)
    {
        Process.Start("C:\\Windows\\System32\\osk.exe");
    }
}
1

There are 1 answers

0
Guy Barker - Microsoft On BEST ANSWER

I expect this is due to the fact that the Windows OSK runs with certain privileges which prevent other apps from sending simulated input to it. It's possible that by using a 3rd party screen reader, you wouldn't hit the issue. Also, depending on your goals, it might be fairly straightforward to build your own OSK, (but that can get more challenging depending on the number of languages you want to support.)

Thanks,

Guy