Jump to content
  • Advertisement
Sign in to follow this  
zgzg2020

"SDL_KEYDOWN" what does it reperesent?

This topic is 3849 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
An SDL_KEYDOWN event occurs when a key is first pressed (unpressed -> pressed), and SDK_KEYUP occurs when a key is released.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!