Re: esc detector wont run -- 'out of scope'

Jonathan Dearborn <[email protected]> Fri, 24 Mar 2017 17:25:54 -0400
Newsgroups gmane.comp.lib.sdl
Message-ID <CA+DSiHYab1=z5PsQyb3+0KgThEg0tCRjrK5bTGZg3=oLyyQa-Q@mail.gmail.com>
--===============5944367297023838620==
Content-Type: multipart/alternative; boundary=001a11494218b684cb054b80a4e6

--001a11494218b684cb054b80a4e6
Content-Type: text/plain; charset=UTF-8

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 <[email protected]> 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
> [email protected]
> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
>
>

--001a11494218b684cb054b80a4e6
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Checking scancodes is a different thing than handling even=
ts.=C2=A0 Unless necessary to achieve an effect (e.g. holding a key while m=
oving the mouse), you should only be using the event structure when in the =
SDL_PollEvent loop.<div><br></div><div>Jonny D</div></div><div class=3D"gma=
il_extra"><br><div class=3D"gmail_quote">On Fri, Mar 24, 2017 at 4:57 PM, s=
peartip <span dir=3D"ltr">&lt;<a href=3D"mailto:[email protected]" targ=
et=3D"_blank">[email protected]</a>&gt;</span> wrote:<br><blockquote cl=
ass=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;p=
adding-left:1ex"><u></u>




	<div>

	<div class=3D"m_-646319085756493572postbody">Thanks every one. In addition=
 to having a window in context I added this small code:<br>
<br>
<div align=3D"center"><br><br><table width=3D"90%" align=3D"center" cellspa=
cing=3D"1" cellpadding=3D"2" border=3D"0" class=3D"m_-646319085756493572cod=
e"><tbody><tr><td><br>
</td></tr><tr>=20
	<td class=3D"m_-646319085756493572code_header" align=3D"left">Code:</td><t=
d><br>
</td></tr><tr><td><br>
</td></tr><tr>
	<td class=3D"m_-646319085756493572code" align=3D"left"><br>
=C2=A0const Uint8 *keys =3D SDL_GetKeyboardState(NULL);<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 SDL_Event e;<br>
.<br>
.<br>
.<br>
<br>
=C2=A0while (SDL_PollEvent(&amp;e)){<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (e=
.type =3D=3D SDL_QUIT){<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 done =3D SDL_TRUE;<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 }<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (k=
eys[SDL_SCANCODE_ESCAPE]){<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 done =3D SDL_TRUE;}<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 }</td=
><td><br>
	</td></tr><tr><td><br>
</td></tr></tbody></table></div></div>
	</div>

<br>______________________________<wbr>_________________<br>
SDL mailing list<br>
<a href=3D"mailto:[email protected]">[email protected]</a><br>
<a href=3D"http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org" rel=3D"nore=
ferrer" target=3D"_blank">http://lists.libsdl.org/<wbr>listinfo.cgi/sdl-lib=
sdl.org</a><br>
<br></blockquote></div><br></div>

--001a11494218b684cb054b80a4e6--

--===============5944367297023838620==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
SDL mailing list
[email protected]
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

--===============5944367297023838620==--