Input Errors

Apr 14, 2013 at 6:58pm
I'm making a program using SDL and everything is going well but everytime that I press any button, my program exits out and returns 3. I tried using sdl_geterror() to find the problem but to no avail. My code for handling input is:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
SDL_GetKeyState(KeyStates);
        while (SDL_PollEvent(&Event))
        {
            //cout<<SDL_GetError()<<endl;
            if (Event.type == SDL_QUIT)
            {
                exit(0);
            }

            else if (Event.type == SDL_KEYDOWN)
            {
                if ( Event.key.keysym.sym == SDLK_f )
                {
                    if (fullscreen)
                        screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, 32, SDL_SWSURFACE);
                    else
                        screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, 32, SDL_SWSURFACE | SDL_FULLSCREEN );

                    fullscreen = !fullscreen;
                }
                else if ( ( KeyStates[SDLK_F4] && ( KeyStates[SDLK_LALT] or KeyStates[SDLK_RALT] ) ) or Event.key.keysym.sym == SDLK_ESCAPE )
                {
                    exit(0);
                }
            }
        }


*Note - I have unicode enabled. Also, pressing f or escape works just fine.
Last edited on Apr 14, 2013 at 11:30pm
Apr 14, 2013 at 11:21pm
bump
Apr 14, 2013 at 11:26pm
I'd run it through a debugger to see what is actually causing the exit.
Apr 15, 2013 at 2:15am
I did that and was able to find and fix the problem. I have another problem though. It seems that my programming isn't able to recognize more than 2 buttons being pressed at the same time but for it to work the way I need it to, it needs to be able to recognize at least 3 buttons pressed at the same time. Any idea on how to fix this?
Apr 15, 2013 at 9:53pm
bump
Apr 16, 2013 at 1:29am
Don't use if-else, just use a series of if statements
Topic archived. No new replies allowed.