Connecting Tech Pros Worldwide Forums | Help | Site Map

SendKeys.SendWait

boeffchen@googlemail.com
Guest
 
Posts: n/a
#1: Oct 1 '07
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


Thorsten Dittmar
Guest
 
Posts: n/a
#2: Oct 3 '07

re: SendKeys.SendWait


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

boeffchen@googlemail.com schrieb:
Quote:
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
>
Closed Thread