Sign in to follow this  
graveyard filla

SDL_EnableKeyRepeat() not working?

Recommended Posts

hi, im working on my 2d online RPG. anyway, i have a chat box, you know the standard one in all online RPG's, where you see other peoples text and type your own. anyway, i want to be able to hold down a key and have it repeat, like i can right now in this window. however, in my game, when i press a key - it only registers one time. i tried calling SDL_EnableKeyRepeat() one time in the begining of my game, but still this doesnt work. i trace through the code, and pressing a button and holding it, only gives me a single SDL_KEYDOWN message when i Poll() for input. does anyone have any clue on what could be the problem? i'll post code if needed. thanks a lot for any help.

Share this post


Link to post
Share on other sites
Hmmm.. I use key repeating for my text input and it works fine - I just followed what it said to do in the SDL docs. Post some code.

Also, you could enable key repeat yourself using the KEY_UP/KEY_DOWN events. On a key down, store the character and add it to the string each game loop until the key up event is detected. Note you'll need a timer to wait like 100ms or so so that the key has tp be held a bit before repeating starts. But yea, having SDL do it would be easier.

Share this post


Link to post
Share on other sites
SDL Wiki tells about SDL_EnableKeyRepeat that:

"Return Value
Returns 0 on success and -1 on failure. "

In my previous game (Tetrowar) I always checked that and it always failed on my computer, but it's because of my stupid error - I've checked whether it returned true and then treated it as success... :-/ Now it works.

Maybe under some OS's it's not implemented(?), what is yours?

Share this post


Link to post
Share on other sites
hh10k was right. i was calling it before initializing SDL. it works great now.. thanks everyone!

btw, what values do you use for this function? like i said, its for a chat text input, like how right now im putting text into this post. im trying to replicate how the text works in this chat pretty much, but im curious what you guys use.

thanks again!

Share this post


Link to post
Share on other sites
Well that's great it's working for you, couse when I will be distributing my game it would be nice if it worked on every possible computer :-) and I wondered is SDL_EnableKeyRepeat really standard.

My values: SDL_EnableKeyRepeat(300, 30) though I wasn't experimenting with them very long.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this