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
2010-08-28 15:58:23
Would this prevent `SendInput` from working, though?
Steven Sudit
2010-08-30 00:33:54
@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
2010-08-30 10:56:20
Sounds like it's not an solution to the OP, but it's interesting.
Steven Sudit
2010-08-30 12:40:41
@Steven: can you explain why it's not a solution to the OP? Perhaps I'm missing something.
James Manning
2010-08-30 14:18:28
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
2010-08-30 20:01:21
@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
2010-08-30 21:57:52
The function does not take any sort of thread or process ID, so it can only operate on the current thread.
Steven Sudit
2010-08-31 15:24:37
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
2010-09-01 04:22:41