T
teclick
Unregistered / Unconfirmed
GUEST, unregistred user!
program Project1;<br><br>{$APPTYPE CONSOLE}<br><br>uses<br> SysUtils, Windows;<br><br><br>procedure MyErrorExit(S: string);<br>begin<br> WriteLn(S);<br>end;<br><br>var<br> hStdin: THANDLE;<br> cNumRead, fdwMode, fdwSaveOldMode, i: DWORD;<br> irInBuf: array[0..128] of _INPUT_RECORD;<br>begin<br> // Get the standard input handle.<br> hStdin := GetStdHandle(STD_INPUT_HANDLE);<br> if hStdin = INVALID_HANDLE_VALUE then<br> MyErrorExit('GetStdHandle');<br><br> // Save the current input mode, to be restored on exit. <br><br> if not GetConsoleMode(hStdin, fdwSaveOldMode) then<br> MyErrorExit('GetConsoleMode');<br> <br> // Enable the window and mouse input events.<br><br> fdwMode := ENABLE_WINDOW_INPUT or ENABLE_MOUSE_INPUT;<br> if not SetConsoleMode(hStdin, fdwMode) then<br> MyErrorExit('SetConsoleMode');<br><br> // Loop to read and handle the input events.<br><br> while True do<br> begin<br><br> // Wait for the events.<br><br> if not ReadConsoleInput(<br> hStdin, // input buffer handle<br> irInBuf[0], // buffer to read into<br> 128, // size of read buffer<br> cNumRead) then // number of records read<br> MyErrorExit('ReadConsoleInput');<br><br> // Dispatch the events to the appropriate handler.<br><br> for i := 0 to cNumRead-1 do<br> begin<br> case irInBuf.EventType of<br> KEY_EVENT: begin// keyboard input<br> //KeyEventProc(irInBuf.Event.KeyEvent);<br> //break;<br> WriteLn('key press');<br> end;<br> {<br> MOUSE_EVENT: begin// mouse input<br> //MouseEventProc(irInBuf.Event.MouseEvent);<br> //break;<br> end;<br> }<br> WINDOW_BUFFER_SIZE_EVENT: begin// scrn buf. resizing<br> //ResizeEventProc(<br> // irInBuf.Event.WindowBufferSizeEvent);<br> //break;<br> end;<br><br> FOCUS_EVENT: begin// disregard focus events<br> end;<br><br> MENU_EVENT: begin// disregard menu events<br> //break;<br> end;<br><br> else MyErrorExit('unknown event type');<br> end;<br> end;<br> end;<br>end.