tags:

views:

78

answers:

1

I'm using SendInput (in C#, using pinvoke) to send text to another application. How can I block the user input so that any text that the user may type when SendInput is working is added after SendInput has finished sending text instead? Currently if the user is typing as the text is sent to the target application, the final result may be inconsistent. Thanks.

+1  A: 

It sounds like you're looking for BlockInput?

http://msdn.microsoft.com/en-us/library/ms646290(VS.85).aspx

James Manning
Would this prevent `SendInput` from working, though?
Steven Sudit
@Steven: no, as long as you're doing it from the same thread, so you would do BlockInput(true); SendInput calls (however many); BlockInput(false);As per the MSDN page:When input is blocked, real physical input from the mouse or keyboard will not affect the input queue's synchronous key state (reported by GetKeyState and GetKeyboardState), nor will it affect the asynchronous key state (reported by GetAsyncKeyState). **However, the thread that is blocking input can affect both of these key states by calling SendInput.** No other thread can do this.
James Manning
Sounds like it's not an solution to the OP, but it's interesting.
Steven Sudit
@Steven: can you explain why it's not a solution to the OP? Perhaps I'm missing something.
James Manning
Or perhaps I'm misunderstanding, but it sounds like her use case involves sending text to another process while preventing inadvertent user input. This would mean that she does not have control over the thread that needs to have its input blocked.
Steven Sudit
@Steven: AFAIK the functions aren't process-specific, they operate at the session level, so AFAIK it should work fine for OP to just call BlockInput before and after their SendInput calls.Note that SendInput also talks about checking the existing keyboard state with GetAsyncKeyState, which the OP may also want to do.
James Manning
The function does not take any sort of thread or process ID, so it can only operate on the current thread.
Steven Sudit
Yes, the point for me is that I want to send text to a target application and prevent the user from typing when the text is being sent to prevent user typed text to alter the text that is entered by using SendInput. I think that probably BlockInput is not the proper solution to it.What should happen is that the keystrokes the user types when text is sent by SentInput and played back when the automatic text insertion is complete.
Andrea Nagar