Reputation: 317
I'm building a C# wpf application that runs on a windows 8 tablet, and I call the virtual keyboard in my application, like this :
Process.Start(Environment.GetFolderPath(Environment.SpecialFolder.System) + System.IO.Path.DirectorySeparatorChar + "osk.exe");
I would like to know if there is a way of setting the position of the keyboard window on my tablet when I open it first. Something like adding XY coordinates to Process.Start
Thanks
Upvotes: 1
Views: 2268
Reputation: 574
Manipulating the OSK window will require your process to be running elevated. (The OSK has certain privileges which means it can't be manipulated by processes which aren't elevated.) But if your app is running elevated, you should find the code below works.
Note that you need to find the OSK window after launching the OSK, rather than getting the MainWindowHandle from the Process object after calling Start(). Due to the way that the OSK starts up, you'll find the HasExited property on the Process object is true, and the MainWindowHandle is not available.
Thanks,
Guy
private void buttonLaunchOSK_Click(object sender, EventArgs e)
{
// Launch the OSK.
Process.Start(Environment.GetFolderPath(Environment.SpecialFolder.System) + System.IO.Path.DirectorySeparatorChar + "osk.exe");
// Wait a moment for the OSK window to be created.
Thread.Sleep(200);
// Find the OSK window.
IntPtr hwndOSK = Form1.FindWindow("OSKMainClass", null);
// Move and size the OSK window.
Form1.MoveWindow(hwndOSK, 0, 0, 800, 300, true);
}
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr FindWindow(string className, string windowTitle);
[DllImport("user32.dll", SetLastError = true)]
internal static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);
Upvotes: 1