Skip to main content
GameDev.net gamedev.net
🔒 Locked

SDL_EnableKeyRepeat() not working?

Started by graveyard filla Dec 3, 2004 at 4:48 PM 5 replies 6k views
Original Post
graveyard filla
graveyard filla
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
Gaiiden
Gaiiden
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
hh10k
hh10k
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.
Koshmaar
Koshmaar
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?
graveyard filla
graveyard filla
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
graveyard filla
graveyard filla
thanks, the SDL default ones seem ok (500 and 30)
FTA, my 2D futuristic action MMORPG

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.