PDA

View Full Version : Can't get SDL_PollEvent to work.



Christian Knudsen
06-04-2008, 09:35 AM
I'm working on migrating a textmode game of mine from BP7.0 to FreePascal. In my BP7.0 code I used a unit for detecting whether or not a key is currently down. I originally thought that I could use the FreePascal Keyboard unit to do the same, but it doesn't seem able to put simultaneous keypresses on the event queue. So... I've decided to try out JEDI-SDL instead. For some reason I can't get the event structure to work:

IF SDL_INIT(SDL_INIT_AUDIO) <0> 0 DO BEGIN
CASE Event.Type_ OF
SDL_KeyDown : BEGIN
CASE Event.Key.KeySym.Sym OF
SDLK_a : A := True;
SDLK_q : Stop := True;
END;
END;
SDL_KeyUp : BEGIN
CASE Event.Key.KeySym.Sym OF
SDLK_a : A := False;
END;
END;
END;
END;
IF A THEN WriteFullLineToScreenBuffer(0,0,3,'A DOWN ')
ELSE WriteFullLineToScreenBuffer(0,0,3,'A NOT DOWN');
UpdateTheScreen;
z.delay(25000);
UNTIL Stop;
END;


I want the above code excerpt to have the two booleans A and B, which both tell me whether or not the A and B keys are currently pressed. However, I always get the 'A NOT DOWN' message and I can't press 'q' to stop the loop from running. What am I doing wrong?