views:

204

answers:

2

Im using SendKey and those functions to send keystrokes to a window located by its Window Name

[DllImport("user32.dll")]
public static extern int FindWindow(
    string lpClassName, // class name 
    string lpWindowName // window name 
    );

[DllImport("user32.dll")]
public static extern int SetForegroundWindow(
    int hWnd // handle to window
    );

Is there another way to send keystroke to a window without putting it in the foreground ?

Im switching between many windows and SendKey is making some errors that I can't control, I can't use SendWait no either putting some thread delays, it has to be the fastest possible ,

Im just looking how it can be done.

+2  A: 

This question has been addressed already on SO:

http://stackoverflow.com/questions/1220820/how-do-i-send-key-strokes-to-a-window-without-having-to-activate-it-using-windows

Jerry Bullard
disappointing yes ...
metro
A: 

I dont think Windows Architecture will allow that, because only forground window is supposed to receive keystrokes or any user acitivity.

Alternate way could be creating virtual destkop, moving your desktop in that virtual desktop and passing keys which could not be visible on screen.

Akash Kava
pretty idea but there is some update ...
metro