Lazarus
Free Pascal => General => Topic started by: mrguzgog on August 15, 2016, 09:45:49 am
-
I have this little function to check if a key is pressed using SDL:
function keyPressed(key: longint): boolean;
begin
while SDL_PollEvent(sdlEvent) = 1 do
begin
if sdlEvent^.type_= SDL_KEYDOWN then
begin
if sdlEvent^.key.keysym.sym = key then exit(true);
end;
end;
exit(false);
end;
If I call it using:
if keyPressed(SDLK_Escape) = true then...
it works fine, but if I call with...
if keyPressed(SDLK_UP) = true then...
it doesn't work. As it compiles properly, SDLK_UP must be defined (somewhere!), maybe I have the wrong type but longint looks to be right.
Can someone tell me what I'm doing wrong please?
-
Oops, forgot to mark this as solved, I re-wrote the keyboard routine as follows and it works fine:
procedure updateKeys();
var
keyPressed: longint;
begin
while SDL_PollEvent(sdlEvent) = 1 do
begin
if sdlEvent^.type_= SDL_KEYDOWN then
begin
keyPressed := sdlEvent^.key.keysym.sym;
case keyPressed of
SDLK_ESCAPE: ...
SDLK_UP: ...
end;
end;
end;
end;