chrknudsen
Programmer
I'm fairly new to Delphi (though I've been programming in Pascal for some time) and to get to know it better, I've decided to make a small console game. The game should basically move a character across the screen according to keypressed up, down, left and right. You have to be able to press multiple keys, so that you can also move diagonally. I've found that I need to use the GetASyncKeyState for this. To test it I wrote the below test program, but I can't get it to work. I can compile it without errors, but when I run it, my console window just freezes, ignoring all keypresses. After a while my keypresses will result in a beep from the computer and I have to forcefully close the console window. Why doesn't the below code work?
Code:
PROGRAM Test;
{$APPTYPE CONSOLE}
USES SysUtils, Windows;
VAR I : Integer;
BEGIN
I := 0;
REPEAT
IF GetAsyncKeyState(VK_RETURN) <> 0 THEN BEGIN
Inc(I);
Write(I);
END;
UNTIL GetAsyncKeyState(VK_ESCAPE) <> 0;
END.