[NTVDM]
[reactos.git] / subsystems / ntvdm / ps2.c
index f5cbef6..034d811 100644 (file)
@@ -265,50 +265,66 @@ VOID KeyboardWriteData(BYTE Data)
     // TODO: Implement PS/2 device commands
 }
 
-VOID CheckForInputEvents()
+DWORD WINAPI InputThreadProc(LPVOID Parameter)
 {
-    PINPUT_RECORD Buffer;
+    INT i;
     HANDLE ConsoleInput = GetStdHandle(STD_INPUT_HANDLE);
-    DWORD i, j, Count, TotalEvents;
-    BYTE ScanCode;
+    INPUT_RECORD InputRecord;
+    DWORD Count;
 
-    /* Get the number of input events */
-    if (!GetNumberOfConsoleInputEvents(ConsoleInput, &Count)) return;
-    if (Count == 0) return;
+    while (VdmRunning)
+    {
+        /* Wait for an input record */
+        if (!ReadConsoleInput(ConsoleInput, &InputRecord, 1, &Count))
+        {
+            DPRINT1("Error reading console input\n");
+            return GetLastError();
+        }
 
-    /* Allocate the buffer */
-    Buffer = (PINPUT_RECORD)HeapAlloc(GetProcessHeap(), 0, Count * sizeof(INPUT_RECORD));
-    if (Buffer == NULL) return;
+        ASSERT(Count != 0);
 
-    /* Peek the input events */
-    if (!ReadConsoleInput(ConsoleInput, Buffer, Count, &TotalEvents)) goto Cleanup;
+        /* Check the event type */
+        switch (InputRecord.EventType)
+        {
+            case KEY_EVENT:
+            {
+                BYTE ScanCode = (BYTE)InputRecord.Event.KeyEvent.wVirtualScanCode;
 
-    for (i = 0; i < TotalEvents; i++)
-    {
-        /* Check if this is a key event */
-        if (Buffer[i].EventType != KEY_EVENT) continue;
+                /* If this is a key release, set the highest bit in the scan code */
+                if (!InputRecord.Event.KeyEvent.bKeyDown) ScanCode |= 0x80;
 
-        /* Get the scan code */
-        ScanCode = (BYTE)Buffer[i].Event.KeyEvent.wVirtualScanCode;
+                /* Push the scan code onto the keyboard queue */
+                for (i = 0; i < InputRecord.Event.KeyEvent.wRepeatCount; i++)
+                {
+                    KeyboardQueuePush(ScanCode);
+                }
 
-        /* If this is a key release, set the highest bit in the scan code */
-        if (!Buffer[i].Event.KeyEvent.bKeyDown) ScanCode |= 0x80;
+                /* TODO: Update the keyboard shift status flags */
 
-        /* Push the scan code onto the keyboard queue */
-        for (j = 0; j < Buffer[i].Event.KeyEvent.wRepeatCount; j++)
-        {
-            KeyboardQueuePush(ScanCode);
-        }
+                /* Keyboard IRQ */
+                PicInterruptRequest(1);
 
-        /* Yes, IRQ 1 */
-        PicInterruptRequest(1);
+                break;
+            }
+
+            case MOUSE_EVENT:
+            {
+                // TODO: NOT IMPLEMENTED
+                UNIMPLEMENTED;
+
+                break;
+            }
 
-        /* Stop the loop */
-        break;
+            default:
+            {
+                /* Ignored */
+                break;
+            }
+        }
     }
 
-Cleanup:
-    HeapFree(GetProcessHeap(), 0, Buffer);
+    return 0;
 }
 
 /* EOF */