I have written a code to position OSK keyboard to the bottom left of the screen when the process has stared. What I have found out is that the code works correctly when I have placed a debugger at the point when the handle is active. But as soon as I remove all the debugging points, and run the windows form, the OSK is not position to bottom left. What I have found is the handle KeyboardWnd has value 0 in it when all the debugging points are removed.
I have tried to delay the process as well to check if the handle loads till then but it does not work. Also "await" is not an option since it needs async for its call
Below is the code for reference
string osk = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), "system32"), "osk.exe");
// start the keyboard process
ProcessStartInfo startInfo = new ProcessStartInfo(osk);
Process tmp = Process.Start(startInfo);
IntPtr KeyboardWnd = GetTabTipWindowHandle();
System.Threading.Thread.Sleep(20);
MoveKeyBoard(KeyboardWnd, 0, Screen.PrimaryScreen.Bounds.Height / 4*3);
The MoveKeyBoard inturn calls for setwindowpos method as below
public static bool MoveKeyBoard(IntPtr hWnd, int ToX, int ToY)
{
return SetWindowPos(hWnd, (IntPtr)0, ToX, ToY, Screen.PrimaryScreen.Bounds.Width/2, Screen.PrimaryScreen.Bounds.Height/4, SWP.NOZORDER | SWP.SHOWWINDOW | SWP.NOCOPYBITS);
}
public static IntPtr GetTabTipWindowHandle()
{
if (TabTip.UseTabTipKeyboard)
return FindWindow("IPTip_Main_Window", null);
else
return FindWindow("OSKMainClass", null);
}