I am writing an on screen keyboard since opening/closing inbuilt on screen keyboard is slow on older machines.
When I click on a button, I want to keep the main window in focus and prevent keyboard window from gaining focus. Similar to the inbuilt Windows 10 on screen keyboard.
https://stackoverflow.com/a/12628353/4077230
protected override void OnActivated(EventArgs e)
{
base.OnActivated(e);
//Set the window style to noactivate.
WindowInteropHelper helper = new WindowInteropHelper(this);
SetWindowLong(helper.Handle, GWL_EXSTYLE,
GetWindowLong(helper.Handle, GWL_EXSTYLE) | WS_EX_NOACTIVATE);
}
private const int GWL_EXSTYLE = -20;
private const int WS_EX_NOACTIVATE = 0x08000000;
[DllImport("user32.dll")]
public static extern IntPtr SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
[DllImport("user32.dll")]
public static extern int GetWindowLong(IntPtr hWnd, int nIndex);
This code makes no difference, keyboard window is still activated on mouse click.