"SDL_KEYDOWN" what does it reperesent?

Started by
0 comments, last by MJP 16 years, 4 months ago
Hello, Does "SDL_KEYDOWN" mean the transition from unpushed -- to --> pushed? Or does it mean the state of the key being DOWN "de-pressed"? If it would be said in computer logic, then is it the transition from 1 to 0? Or is it the steady state of it being at 1? I believe it is the first. Because if it was the second possibility then SDL_KEYUP would invoke all unpressed keys to be true all the time, no? --------------- I have another question that is relating to this one. I am currently writing a Tic Tac Toe game. And I implementing the controls. I wrote it in two different ways. currentPosition[ 0 ] is the x coordinate on the Tic Tac Toe board. --- Type one --- if( event.type == SDL_KEYDOWN ) { switch( event.key.keysym.sym ) { case SDLK_LEFT: if( currentPosition[ 0 ] > 0 ) { currentPosition[ 0 ]--; } break; . . . --- End --- --- Type two --- if( event.type == SDL_KEYDOWN ) { switch( event.key.keysym.sym ) { case SDLK_LEFT: xDisposition -= 1; break; . . . if( event.type == SDL_KEYUP ) { switch( event.key.keysym.sym ) { case SDLK_LEFT: xDisposition += 1; break; . . . move_courser( xDisposition, yDisposition ); void move_courser( int xShift, int yShift ) { currentPosition[ 0 ] += xShift; currentPosition[ 1 ] += yShift; if( ( currentPosition[ 0 ] < 0 ) | ( currentPosition[ 0 ] > 2 ) ) { currentPosition[ 0 ] -= xShift; } } --- End --- I left out the y movement for simplicity The first type yields the better result. The result there is when a key is pressed (even kept de-pressed) the shift is always one cell at a time. The second type yields an unusable result for a Tic Tac Toe control. When a key is pressed (de-pressed) it goes VERY fast over the board, and only stops when the key becomes unpressed. I read in lazy foo's tutorials that event handling and logic must be separated. The first type I wrote by my own way. But then I felt that I didn't separate the logic from the event handling so I had to change it. I went reading through his tutorials again, and I rewrote it in this way trying to imitate his method. Could someone kindly explain why are the results differ in these two types of code? Regards
Advertisement
An SDL_KEYDOWN event occurs when a key is first pressed (unpressed -> pressed), and SDK_KEYUP occurs when a key is released.

This topic is closed to new replies.

Advertisement