Funnily enough, it's very hard to use IsKeyDown etc. in cases, so I though why not make something that runs through all the keys and stops when it finds a key that is down or in GetKeysDown, all the keys that are down. With these functions, it makes it very easy to use in cases. So, here we go:
SCAR Code:
function GetKeyDown: Char;
var
i: Integer;
begin
repeat
for i:= 0 to 127 do
if IsKeyDown(Chr(i)) then
begin
Result := Chr(i);
Exit;
end;
until(IsKeyDown(Result))
end;
SCAR Code:
function GetKeysDown: array of Char;
var
i: Integer;
begin
for i:= 0 to 127 do
if IsKeyDown(Chr(i)) and IsKeyDown(Chr(i)) then
begin
SetArrayLength(Result,High(Result)+2);
Result[High(Result)] := Chr(i);
end;
end;
If you want to test them both (though more GetKeysDown), you can run the following script, and start typing to see the keys come up in the Debug box
SCAR Code:
program New;
var
i: Integer;
CharsDown: array of Char;
function GetKeyDown: Char;
var
i: Integer;
begin
repeat
for i:= 0 to 127 do
if IsKeyDown(Chr(i)) then
begin
Result := Chr(i);
Exit;
end;
until(IsKeyDown(Result))
end;
function GetKeysDown: array of Char;
var
i: Integer;
begin
for i:= 0 to 127 do
if IsKeyDown(Chr(i)) and IsKeyDown(Chr(i)) then
begin
SetArrayLength(Result,High(Result)+2);
Result[High(Result)] := Chr(i);
end;
end;
begin
repeat
ClearDebug;
CharsDown:= GetKeysDown;
for i:= 0 to High(CharsDown) do
Writeln(CharsDown[i]);
SetArrayLength(CharsDown,0);
Wait(500);
until (GetKeyDown = 'q')
end.
Which will run until you push down the 'q' button.
Enjoy