SDL_EnableKeyRepeat() not working?

Started by
5 comments, last by graveyard filla 19 years, 4 months ago
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.
FTA, my 2D futuristic action MMORPG
Advertisement
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.

Drew Sikora
Executive Producer
GameDev.net

It seems to work fine for me. The only thing I can think of is that you're calling SDL_EnableKeyRepeat before initialising SDL_INIT_VIDEO.
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?
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!
FTA, my 2D futuristic action MMORPG
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.

thanks, the SDL default ones seem ok (500 and 30)
FTA, my 2D futuristic action MMORPG

This topic is closed to new replies.

Advertisement