Re: SDL, keyboard and event handling

new topic     » goto parent     » topic index » view thread      » older message » newer message

Hi

Yes, but it's a union I can access now, thanks to you pointing me in the right direction with the peek type.

All I need is the event type for a 'press any key function' doing it this way

"The SDL_Event structure is the core of all event handling in SDL. SDL_Event is a union of all event structures used in SDL."

So make an event memory area big enough to hold the event union, and treat the bit I'm interested in like a structure - the last element of the SDL_Event structure is another structure, which is wher it becomes a union. (Probably teaching Granny to suck eggs at this point, but I've always had a conceptual difficulty grasping this)

atom ev_type = 0, ev 
 
ev = allocate(1024) 
while SDL_WaitEvent(ev) do 
    ev_type = peek4u(ev) 
        if ev > 0 then 
            ev_type = peek4u(ev)     4 byte unsigned int (C_UINT32) 
            printf(1, "%d, %d, %d\n", {ev, SDL_KEYDOWN, ev_type}) --lets see what it's spewing out 
            --if wait_key() then end if       --console 
            if ev_type = SDL_KEYDOWN then exit end if  -- comment this out to see all the spew 
        end if 
end while     
 
free(ev)  --should probably free it too 
return ev_type 
 

It was the allocate memory bit that I was missing. Now just need to trim and adapt the output for use. I appreciate that ffi, and cffi/c-struct should be easier to do this too.

Many thanks Chris

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu