I am running a keyboard hook that, when required, launches a process. That process is a simple C# Windows form with a form on which there is a listview . . . nothing fancy.
It is desired that this form immediately have the focus so the user can begin using the keyboard UP/DOWN arrow keys without having to first "activate" the form. I want to remove the requirement that the user first have to left click on the form to give it the focus before they can begin using the UP/DOWN keys.
It seems that no matter what I try, the form is never the topmost window. The user is always forced to have to left click on this window first.
I've tried the following:
Setting the "Topmost" property of the form to "true" in the form's Design mode.
Calling the following in the form's Load() event:
SetWindowPos(this.Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
I've even tried elevating the Priority to "RealTime" when it's launched.
I launch the process using the following:
ProcessStartInfo Prog2 = new ProcessStartInfo();
Prog2.UseShellExecute = false;
Prog2.FileName = "c:\someapp.exe";
Prog2.Arguments = "1";
Process p2 = Process.Start(Prog2);
p2.PriorityBoostEnabled = true;
p2.PriorityClass = ProcessPriorityClass.RealTime;
The TaskManager has a "SwitchTo" button which always works on any process running. Is there any way to programatically simulate the "Switch To" functionality within the calling program?
Thanks in advance,