You must zero-out the whole structure(s) once before filling it.
I would send it as an array of structures. And you should send the key strokes only if the console window you are looking for is activated and has the keyboard focus, so check the return value of SetForegroundWindow.
Didn't my example work for you ?