What happens is I press right for a fraction of a second then release and my character moves to the right, as it is supposed to. I then press right again but this time for 5 seconds. My character moves immediately to the right and keeps moving with no pause between the first movement and the rest, as it is supposed to. But after 5 seconds of pressing right I then release the key and press left, but my character still keeps moving to the right for another 6 seconds. This effect is worse the longer I press the key. Why is that? I checked the boolean variables I am using to track the pressed and not pressed status of my keys and it seems like the status doesn't change until after the aforementioned 6 seconds during which the character keeps walking right although I am pressing left. However, key presses are still being detected quickly and on time in each iteration of the main game loop.
Based on my checks, key presses are still being checked quickly at each iteration of the main loop, and so is the key down/pressed status of keyboard keys. However, the key up/released status of keys is only checked until after the 6 seconds mentioned. Further checks showed that SDL2 poll event still reports a keydown status even though I am not pressing any keys and only reports a keyup after the 6 seconds. Is it windows 10 interfering with my program? It's like there's another program that keeps pressing right (same issue with other keys) eventhough I am no longer physically pressing that key.
I would appreciate your help and advice. Thank you.
I am programming in Free Pascal using SDL2. Below is a sample of my keyboard and other inputs procedure:
if sdl_pollevent(sdlevent)=1 then
begin
{ writeln(sdlevent^.type_,' ',sdl_keydown,' ',sdl_keyup); }
if sdlevent^.type_=sdl_keydown then
begin
joystickactive:=false;
{ writeln(sdlevent^.key.keysym.sym); }
{ writeln(sdl_getkeyname(sdlevent^.key.keysym.sym)); }
enterkeyintf:=false;
if enterkeyintf=true then
begin
assign(t[1],'tf\tf0.tf');
append(t[1]);
settextbuf(t[1],bufin);
writeln(t[1],sdlevent^.key.keysym.sym);
writeln(t[1],sdl_getkeyname(sdlevent^.key.keysym.sym));
close(t[1]);
end;
o[1]:=0;
repeat
o[1]:=o[1]+1;
if sdlevent^.key.keysym.sym=keycode[o[1]] then keybool[o[1]]:=true;
until o[1]=totalkeys;
o[1]:=0;
repeat
o[1]:=o[1]+1;
if sdlevent^.key.keysym.sym=alphanumm[o[1]] then alphanumbool[o[1]]:=true;
until o[1]=totalalphanum;
end;
if sdlevent^.type_=sdl_keyup then
begin
joystickactive:=false;
o[1]:=0;
repeat
o[1]:=o[1]+1;
if sdlevent^.key.keysym.sym=keycode[o[1]] then keybool[o[1]]:=false;
until o[1]=totalkeys;
o[1]:=0;
repeat
o[1]:=o[1]+1;
if sdlevent^.key.keysym.sym=alphanumm[o[1]] then alphanumbool[o[1]]:=false;
until o[1]=totalalphanum;
end;
end;