Fixed KEYSTACK /i with repeat count sends wrong keys

#1
Whenever/however I use "/i" with keystack and with repeat counts, it sends the wrong keys. "/i=pid,timeout" is particularly odd. Is the "=" really required?

1534526168508.png

1534526228898.png

1534526276420.png

Even without repeat counts, the "=" is problematic.

1534527264778.png
 
#3
There's no more mangled text, but in more than an hour of experimenting I can see no evidence that /i works (does anything). Here's just one of many that I tried.
Code:
start excel & keystack /i=%_startpid,5000 "foo"
"foo" doesn't show up anywhere.

According to WinDbg, TCC doesn't call WaitForInputIdle().
 
#4
This does what you likely expect:
Code:
start notepad & keystack /i=%_startpid,5000 "foo"
.
When Excel starts, it is not processing printable characters for insertion anywhere. Notepad, when it starts (without a named file or when told to edit an existing file), is immediately prepared to insert such characters into its text box.
 
#5
This does what you likely expect:
Code:
start notepad & keystack /i=%_startpid,5000 "foo"
.
When Excel starts, it is not processing printable characters for insertion anywhere. Notepad, when it starts (without a named file or when told to edit an existing file), is immediately prepared to insert such characters into its text box.
Well, yes, but it's not because of the "/i" (which I don't think is working). As you pointed out, notepad is ready quickly enough; it works without "/i". At least here, it's needed with Excel (and doesn't work). As I said earlier, according to WinDbg, TCC doesn't call WaitForInputIdle, even when "/i" is used.

To see if it worked in principle, I overloaded my WAIT plugin with (after some parsing and opening a process) the likes of
Code:
        WaitForInputIdle(hProc, dwTimeout);
        CloseHandle(hProc);
And this (below) does work.
Code:
start excel & wait /i %_startpid 5000 & keystack "foo"
while both of these fail.
Code:
start excel & keystack "foo"
start excel & keystack /i=%_startpid,5000 "foo"
 
#6
I still can't see KEYSTACK work with /i. As I said before,
Code:
start excel & keystack "foo"
doesn't work while using my own wrapper for WaitForInputIdle
Code:
start excel & wait /i %_startpid 5000 & keystack "foo"
does work ("foo" appears in excel).

When I do this with build 29
Code:
start excel & keystack /i=%_startpid,5000 "foo"
no "foo" appears in excel (or anywhere else).

Watching with WinDbg I can see TCC doing everything right! ... OpenProcess with the right PID and PROCESS_QUERY_INFORMATION (which is sufficient) ... that succeeds ... then WaitForInputIdle with the right HANDLE and timeout ... that succeeds (returns 0) ...
 
#7
Having experimented quite a bit with KEYSTACK /i and my own WAIT /i, and having read a couple interesting installments of "The New Old Thing" (Raymond Chen, on WaitForInputIdle, 3/25-3/26 2010), I've come to the opinion that WaitForInputIdle is not very a reliable way of waiting for the window/thread that you want to get keystrokes to actually be in a state to receive keystrokes.