Re: SDL, keyboard and event handling
- Posted by ChrisB (moderator) Nov 01, 2022
- 1006 views
Added another couple of little helper routines
--------------------------------------------------------------------------- global function M_get_key() --like M_wait_key(), but doesn't wait --------------------------------------------------------------------------- atom key = 0, ev_type = 0 integer scanning = 1, scancode = 0 SDL_PumpEvents() key = SDL_GetKeyboardState(key) --if peek(key+SDL_SCANCODE_ESCAPE) > 0 then -- scanning = 0 --end if for i = 4 to 99 do if peek(key + i) > 0 then scanning = 0 scancode = i end if end for return scancode end function --------------------------------------------------------------------------- global procedure M_flush_key_buffer() --------------------------------------------------------------------------- while M_get_key() do end while end procedure
Is there a better SDL way to do these - SDL_FlushEvents(SDL_FIRSTEVENT, SDL_LAST_EVENT) doesn't seem to work as expected.