[SDL] esc detector wont run -- 'out of scope'

Clangray clangray at fastmail.com
Sat Mar 25 11:23:36 PDT 2017


Jonny D is this an appropriate way to handle a keypress and exit
the program?


--

  Gray Family

  clangray at fastmail.com







On Fri, Mar 24, 2017, at 05:25 PM, Jonathan Dearborn wrote:

> Checking scancodes is a different thing than handling events.  Unless
> necessary to achieve an effect (e.g. holding a key while moving the
> mouse), you should only be using the event structure when in the
> SDL_PollEvent loop.
> 

> Jonny D

> 

> On Fri, Mar 24, 2017 at 4:57 PM, speartip
> <clangray at fastmail.com> wrote:
>> __

>> Thanks every one. In addition to having a window in context I added
>> this small code:
>> 

>> 

>> 

>> 
>> 
>> Code:
>> 
>> 

>> 

>>  const Uint8 *keys = SDL_GetKeyboardState(NULL);

>>          SDL_Event e;

>>  .

>>  .

>>  .

>> 

>>   while (SDL_PollEvent(&e)){

>>                      if (e.type == SDL_QUIT){

>>                          done = SDL_TRUE;

>>                      }

>>                      if (keys[SDL_SCANCODE_ESCAPE]){

>>                          done = SDL_TRUE;}

>>                      }
>> 
>> 

>> 

>> _______________________________________________

>>  SDL mailing list

>> SDL at lists.libsdl.org

>> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

>> 

> _________________________________________________

> SDL mailing list

> SDL at lists.libsdl.org

> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20170325/e6c7ef90/attachment.htm>


More information about the SDL mailing list