How to select and focus at a process and Hold down a key
Hi i need to now how to holed down a key. To other programs windows...
if i us SendKeys.Send i need to crate a for to send that constant.
SendKeys.Send("{W}");
But i want to Hold down a key. How i do now
and how to fockus att a process
using System.Diagnostics;
Process.GetProcesses(firefox.exe);
Process[] firefoxProcess = ......
Plz help me...

How to select and focus at a process? and Hold down a key?
fantasimus
To activate a specific window you can use the FindWindow and SetForegroundWindow API.
Usually you don't need to hold down a key: with the exception of the control keys (ctrl, shift, alt), holding down a key simply means that the keys are repeated at a rate determined by the keyboard settings. You can easily repeat a key either calling SendKeys.Send several times at prefixed intervals, or specify a count in the key string, for instance: SendKeys.Send ("{LEFT 10}");
If you really want to mimic the behaviour of the keyboard, you need to call the SendMessage API, sending the WM_KEYDOWN and WM_KEYUP messages with the appropriate parameters. The good part about this approach is that, although you will need the Window handle of the window you want to send your keys to, you can send the messages to a window that is not foreground. Conversely, SendKeys.Send does not need the window handle, but may be disrupted by unexpected pop-ups.
To bring a window to the foreground, you need to call the FindWindow API (to get the window handle) and SetForegroundWindow API to make it foremost.
You can get the handle of the main window of a process using something similar to what you have written:
IntPtr windowHandle = IntPtr.Zero;
Process [] processes = Process.GetProcessesByName ("myapp");
if (processes.Length > 0) {
windowHandle = processes [0].MainWindowHandle;
}
HTH
--mc
James Hunter
I noticed that if the process is minimized in the System Tray, that the 'MainWindowHandle' is 0, and also the 'MainWindowTitle' = "". The Id is valid, but if you try to call something such as 'Instance.AppActivate' using that Id, an exception is thrown.
Do you know how to get the Windows handle for an application that is in the System Tray
Thanks.