[SDL] Handling keys?
Leo M. Cabrera
leo28c at gmail.com
Mon Feb 12 19:05:19 PST 2007
I'm sorry for having wasted your time, it does work... Well, not really,
but it seems to be a problem with the Lua port... :-/
None of the letter keys work, so I'm stuck with the arrows... Gotta look
into that, but thanks though! ;-)
matt wrote:
> L-28C wrote:
>
>> Hello everyone! :-D
>>
>> Okay. What was the code to get a key while it is pressed, instead of
>> just shooting the event when it's first pressed?
>>
>> I tried this, but it doesn't seem to work: (I key)
>>
>> ----------
>> iPressed = false
>>
>> while true do
>>
>> while (SDL.SDL_PollEvent(event) == 0) do
>> -- Render the screen
>> render()
>> -- Move the ball
>> moveBall()
>> SDL.SDL_Delay(100)
>> end
>>
>> if event.type == SDL.SDL_KEYDOWN then
>>
>> key = event.key.keysym.sym
>> if key == SDL.SDLK_I then
>> iPressed = true
>> else
>> iPressed = false
>> end
>>
>>
>> if iPressed then
>> -- Do my stuff here
>> end
>> end
>> --------
>>
>> OK, I know this isn't C++, but it should be pretty straight-forward if
>> you know that... And I know C++, so you can use that in your answers. :-P
>>
>> So what's the correct code? Thanks! ;-)
>>
>> _______________________________________________
>> SDL mailing list
>> SDL at lists.libsdl.org
>> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
>>
>>
>>
> do you have the actual code that doesnt work ? perhaps post a tarball
> on the web so we can look at it ?
>
> also, i use a thread for the rendering code instead of a delay.
>
> here is my main loop (still working on the core so this it temporary code):
>
> while(!quit)
> {
> SDL_WaitEvent(&event);
>
> switch (event.type)
> {
> case SDL_KEYUP:
> do_key_up(key_event(event.key.keysym.sym));
> break;
> case SDL_KEYDOWN:
> do_key_down(key_event(event.key.keysym.sym));
> break;
> case SDL_QUIT:
> quit = -1;
> }
> }
>
>
> matt
> _______________________________________________
> SDL mailing list
> SDL at lists.libsdl.org
> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
>
>
More information about the SDL
mailing list