Results 1 to 9 of 9

Thread: Can't get SDL_PollEvent to work.

  1. #1

    Can't get SDL_PollEvent to work.

    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:

    [pascal] IF SDL_INIT(SDL_INIT_AUDIO) < 0 THEN BEGIN
    { quit}
    END
    ELSE BEGIN
    A := False;
    B := False;

    SDL_EnableUNICODE(1);
    REPEAT
    ClearScreenBuffer;
    WHILE SDL_PollEvent(@Event) > 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;
    [/pascal]

    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?

    Also, I couldn't find any documentation for GetKeyStates in the JEDI docs only in the SDL for C docs. Can't this function be used in FreePascal?
    Laserbrain Studios - Currently developing Hidden Asset!
    Ascii Sector
    - Real-time roguelike in space!

  2. #2

    Can't get SDL_PollEvent to work.

    And you had A pressed ... for 25 seconds?

    First I'd try to disable Unicode.

    Secondly I would write "SDL_PollEvent(@Event) <> 0" instead of ">0"
    since it resembles Cs perverted bool=int=whatever behaviour better.

  3. #3

    Can't get SDL_PollEvent to work.

    I don't need to have A pressed for 25 seconds. z.delay is a microsecond timer, so I would only have to press A for 25 milliseconds. I've tried disabling Unicode, but that didn't do anything. Neither did using <> instead of >.
    Laserbrain Studios - Currently developing Hidden Asset!
    Ascii Sector
    - Real-time roguelike in space!

  4. #4

    Can't get SDL_PollEvent to work.

    Anybody else have any idea why this isn't working? I've had to put my plans to switch from BP7.0 to FreePascal completely on hold because of this...
    Laserbrain Studios - Currently developing Hidden Asset!
    Ascii Sector
    - Real-time roguelike in space!

  5. #5

    Can't get SDL_PollEvent to work.

    At least your SDL_Loop looks perfectly correct to me (except for the "<>" thingy).
    However your screenbuffer-stuff looks unfamiliar ... maybe try a simpler method (writeln).

  6. #6

    Can't get SDL_PollEvent to work.

    I've had some trouble with this too. It looks like it's not catching any keypresses at all. This might be because SDL events are linked to SDL_Video, which you haven't SDL_Init-ed.

    I'm not completely certain, but I think SDL can only catch events if a screen (window) created by SDL currently has input focus.

  7. #7

    Can't get SDL_PollEvent to work.

    Sounds good to me. Try this:
    http://www.pascalgamedevelopment.com...fbb3922a#42877

    The handle to your own application can be read from
    system.MainInstance

    This way you don't need to init SDL_Video or create a window with SDL - only in case it works, of course.

  8. #8

    Can't get SDL_PollEvent to work.

    I'll have a go at this tonight. Thanks for the suggestions!
    Laserbrain Studios - Currently developing Hidden Asset!
    Ascii Sector
    - Real-time roguelike in space!

  9. #9

    Can't get SDL_PollEvent to work.

    I took a look at the link and googled "sdl_setenv", but I have no clue what to do. How do I set focus to my console application so SDL can capture events without having to create a window with SDL or initialize SDL_Video?
    Laserbrain Studios - Currently developing Hidden Asset!
    Ascii Sector
    - Real-time roguelike in space!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •