SendKeys.SendWait

B

boeffchen

Hello,

I am trying to send keys to a window using the method above, though I
am encountering timing issues, which msdn warned me of before.
The way I tried to fix it is polling if the window I want to send keys
to is really the focus via:
while (GetForegroundWindow() != theHwndWeWant)
Thread.Sleep(0);
Thread.Sleep(0); // to give some extra time
SendKeys.SendWait("our keys");
SetForegroundWindow(the old one :p);
[... more stuff ...]

For windows vista the above code works fine for me. For Windows XP it
doesn't.
Does anyone have an idea of checks I could add to make sure everything
is sent to the correct window?

Thanks in advance
 
T

Thorsten Dittmar

Hi,

at work we had a similar problem, only we had to programmatically
activate the target window. This involved a whole bunch of code, as
Windows 2000 and XP don't always act as you'd expect.

Basically we called ActivateWindow and related API in a loop and checked
for the foreground window handle like you do. What happens if you don't
use Thread.Sleep(0) but Thread.Sleep(10) for example?

Regards
Thorsten
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top