I'm running a virtual keyboard when a textbox gets focus, but then keyboard app is focused and will not transfer keys to textbox. If I click on textbox to activate it, everything is fine, but I want my application to get activated after vKeyboard process runs. This is what I've tried so far:
[DllImport("user32.dll")]
static extern bool PostMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);
[DllImport("user32.dll")]
static extern bool SetForegroundWindow(IntPtr hWnd);
[DllImport("user32.dll")]
internal static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
....
vKeyboard = Process.Start(keyboardPath);
SetFocusToApplication(handle);
....
private static void SetFocusToApplication(IntPtr handle)
{
Process currentProcess = Process.GetCurrentProcess();
IntPtr hWnd = currentProcess.MainWindowHandle;
if (hWnd != IntPtr.Zero)
{
SetForegroundWindow(handle);
ShowWindow(hWnd,3);
}
}
I also tried sending Alt + Tab to keyboard process, but it doesn't work:
private static void AltTab(IntPtr handle)
{
vKeyboard.WaitForInputIdle();
int WM_SYSCOMMAND = 0x0112;
int SC_PREVWINDOW = 0xF050;
PostMessage(vKeyboard.MainWindowHandle, WM_SYSCOMMAND, (IntPtr)SC_PREVWINDOW, (IntPtr)0);
}
PS: I do have the source code for virtual keyboard if I can do anything from there to deactivate itself, still fine. let me know. Also keyboard top most property is set to true, not sure if that makes any different.
This is the code that I'm trying and doenst work in button click:
Process vKeyboard;
string keyboardPath = Application.StartupPath + "\\vKeyboard.exe";
vKeyboard = Process.Start(keyboardPath);