سلام!

پاسخ تمرین سری قبل را می توانید در کد زیر مشاهده کنید؛

#include "SDL/SDL.h"

#include <iostream>

using namespace std;

void closeProgram(){
    SDL_Quit();
    exit( 0 );
}

void check( SDL_Surface *screen ){
    if ( screen == NULL ){
        cout << SDL_GetError() << endl;
        closeProgram();
    }
}

int main(){
    SDL_Init( SDL_INIT_EVERYTHING );

    SDL_Surface *screen = SDL_SetVideoMode( 640, 480, 32, SDL_HWSURFACE );
    check( screen );
    SDL_Event event;
    bool buttons[4] = {false};
    
    while ( 1 ){
        while ( SDL_PollEvent( &event ) ){

            if ( event.type == SDL_QUIT )
                closeProgram();

            if ( event.type == SDL_MOUSEBUTTONDOWN )
                buttons[ event.button.button ] = true;
            
            if ( event.type == SDL_MOUSEBUTTONUP )
                buttons[ event.button.button ] = false;

            if ( event.type == SDL_MOUSEMOTION ){
                if ( !buttons[SDL_BUTTON_LEFT] && !buttons[SDL_BUTTON_RIGHT] && !buttons[SDL_BUTTON_MIDDLE] )
                    cout << "No Buttons";
                if ( buttons[ SDL_BUTTON_LEFT ] )
                    cout << "Left";
                if ( buttons[SDL_BUTTON_MIDDLE ] )
                    cout << "Middle";
                if ( buttons[ SDL_BUTTON_RIGHT ] )
                    cout << "Right";
                cout << endl;
            }
        }
    }

    closeProgram();
}

موفق باشید!