+
+ /* Go to the next event */
+ ++InputEvent;
+ }
+
+ return NumEventsToWrite;
+}
+
+/*
+ * This post-processing code MUST be IN consrv ONLY
+ */
+static VOID
+PostprocessInput(PCONSOLE Console)
+{
+ CsrNotifyWait(&Console->ReadWaitQueue,
+ FALSE,
+ NULL,
+ NULL);
+ if (!IsListEmpty(&Console->ReadWaitQueue))
+ {
+ CsrDereferenceWait(&Console->ReadWaitQueue);
+ }
+}
+
+NTSTATUS
+ConioAddInputEvents(PCONSOLE Console,
+ PINPUT_RECORD InputRecords, // InputEvent
+ ULONG NumEventsToWrite,
+ PULONG NumEventsWritten,
+ BOOLEAN AppendToEnd)
+{
+ NTSTATUS Status = STATUS_SUCCESS;
+ ULONG i = 0;
+ BOOLEAN SetWaitEvent = FALSE;
+
+ if (NumEventsWritten) *NumEventsWritten = 0;
+
+ /*
+ * This pre-processing code MUST be IN consrv ONLY!!
+ */
+ NumEventsToWrite = PreprocessInput(Console, InputRecords, NumEventsToWrite);
+ if (NumEventsToWrite == 0) return STATUS_SUCCESS;
+
+
+ /*
+ * When adding many single events, in the case of repeated mouse move or
+ * key down events, we try to coalesce them so that we do not saturate
+ * too quickly the input buffer.
+ */
+ if (NumEventsToWrite == 1 && !IsListEmpty(&Console->InputBuffer.InputEvents))
+ {
+ PINPUT_RECORD InputRecord = InputRecords; // Only one element
+ PINPUT_RECORD LastInputRecord;
+ ConsoleInput* ConInRec; // Input
+
+ /* Get the "next" event of the input buffer */
+ if (AppendToEnd)
+ {
+ /* Get the tail element */
+ ConInRec = CONTAINING_RECORD(Console->InputBuffer.InputEvents.Blink,
+ ConsoleInput, ListEntry);
+ }