He don't want [event]

hi,
I have two probs first is whit event . just this little prog

#include
#include <SDL/SDL.h>
using namespace std;
SDL_Surface* ECRAN;
const int LARG = 300;
const int LONG = 300;

int main(int argc, char* argv[])
{
SDL_Init(SDL_INIT_EVERYTHING);
atexit(SDL_Quit);
SDL_Rect rec; rec.x = 0; rec.y =0; rec.w=LARG; rec.h = LONG;
ECRAN = SDL_SetVideoMode(LARG,LONG,0,SDL_ANYFORMAT);
SDL_FillRect(ECRAN, &rec, 0x12345678);
SDL_Flip(ECRAN);
SDL_Event event;
while(1)
{
SDL_WaitEvent(&event);
if(event.type == SDL_QUIT){cout << “quit prog”<< endl;return 0;}
if(event.type == SDLK_F1) cout << “tape F1” << endl;
if(event.type == SDLK_BACKSPACE) cout << “tape BACKSPACE” << endl;
}

}

the SDL_QUIT work perfecly, but nothing arrive for the other . I even
have that msg when I compil

main.cc:22: warning: comparaison is always false due to limited range of
data

line 22 is if(event.type == SDLK_F1) cout << “tape F1” << endl;

is there a error in my code??

thanks.

a++

The problem is, that SDLK_F1 is an “SDLKey” and no “SDL_Event.Type”, so a comparision makes no sense.

A proper Event-Type would be SDL_KEYDOWN or SDL_KEYUP for example.
So you should first check if the Keyboard threw an Event,
and then check which key was pressed or released.

Example:

if(event.type == SDL_KEYDOWN)
{
switch( event.key.keysym.sym )
{
case SDLK_F1:
cout << “F1 is pressed” << endl;
break;

	case SDLK_SDLK_BACKSPACE:
		cout << "Backspace is pressed" << endl;
	break;

	// .... and so on
	// check the following links for more information
}

}

Further information can be found here:
http://sdldoc.csn.ul.ie/sdlevent.php
http://sdldoc.csn.ul.ie/sdlkey.php
(read the “User Contributed Notes” at the bottom of the page-content)

Nils>hi,

I have two probs first is whit event . just this little prog

#include
#include <SDL/SDL.h>
using namespace std;
SDL_Surface* ECRAN;
const int LARG = 300;
const int LONG = 300;

int main(int argc, char* argv[])
{
SDL_Init(SDL_INIT_EVERYTHING);
atexit(SDL_Quit);
SDL_Rect rec; rec.x = 0; rec.y =0; rec.w=LARG; rec.h = LONG;
ECRAN = SDL_SetVideoMode(LARG,LONG,0,SDL_ANYFORMAT);
SDL_FillRect(ECRAN, &rec, 0x12345678);
SDL_Flip(ECRAN);
SDL_Event event;
while(1)
{
SDL_WaitEvent(&event);
if(event.type == SDL_QUIT){cout << “quit prog”<< endl;return 0;}
if(event.type == SDLK_F1) cout << “tape F1” << endl;
if(event.type == SDLK_BACKSPACE) cout << “tape BACKSPACE” << endl;
}

}

the SDL_QUIT work perfecly, but nothing arrive for the other . I even
have that msg when I compil

main.cc:22: warning: comparaison is always false due to limited range of
data

line 22 is if(event.type == SDLK_F1) cout << “tape F1” << endl;

is there a error in my code??

thanks.

a++


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

thanks a lots, thats work

Nils Wogatzky wrote:>The problem is, that SDLK_F1 is an “SDLKey” and no “SDL_Event.Type”, so a comparision makes no sense.

A proper Event-Type would be SDL_KEYDOWN or SDL_KEYUP for example.
So you should first check if the Keyboard threw an Event,
and then check which key was pressed or released.

Example:

if(event.type == SDL_KEYDOWN)
{
switch( event.key.keysym.sym )
{
case SDLK_F1:
cout << “F1 is pressed” << endl;
break;

  case SDLK_SDLK_BACKSPACE:
  	cout << "Backspace is pressed" << endl;
  break;

  // .... and so on
  // check the following links for more information

}
}

Further information can be found here:
http://sdldoc.csn.ul.ie/sdlevent.php
http://sdldoc.csn.ul.ie/sdlkey.php
(read the “User Contributed Notes” at the bottom of the page-content)

Nils

hi,
I have two probs first is whit event . just this little prog

#include
#include <SDL/SDL.h>
using namespace std;
SDL_Surface* ECRAN;
const int LARG = 300;
const int LONG = 300;

int main(int argc, char* argv[])
{
SDL_Init(SDL_INIT_EVERYTHING);
atexit(SDL_Quit);
SDL_Rect rec; rec.x = 0; rec.y =0; rec.w=LARG; rec.h = LONG;
ECRAN = SDL_SetVideoMode(LARG,LONG,0,SDL_ANYFORMAT);
SDL_FillRect(ECRAN, &rec, 0x12345678);
SDL_Flip(ECRAN);
SDL_Event event;
while(1)
{
SDL_WaitEvent(&event);
if(event.type == SDL_QUIT){cout << “quit prog”<< endl;return 0;}
if(event.type == SDLK_F1) cout << “tape F1” << endl;
if(event.type == SDLK_BACKSPACE) cout << “tape BACKSPACE” << endl;
}

}

the SDL_QUIT work perfecly, but nothing arrive for the other . I even
have that msg when I compil

main.cc:22: warning: comparaison is always false due to limited range of
data

line 22 is if(event.type == SDLK_F1) cout << “tape F1” << endl;

is there a error in my code??

thanks.

a++


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl