SDL keyboard input

Started by
3 comments, last by Lazy Foo 17 years, 6 months ago
Greetings all! I am attempting to write a text-based adventure game with my SDL engine. Problem is, I need a good way to get the keyboard input. I've played around with ways of polling the keys and adding the SDL_GetKeyName() char to a vector. I'm wondering if anyone knows a better way? I'm unsure of how to handle key modifiers, backspaces, spaces, etc. All of the tuts I've found only deal with the usual game input (left, right movement, etc.); none deal with actually getting a string of text input. All replies are appreciated, ~Neith
Advertisement
I have an example of a basic string input class here.

Learn to make games with my SDL 2 Tutorials

Great, that works. Thanks!

There's a slight typo in that tutorial: the comment for the line

else if( ( event.key.keysym.unicode >= (Uint16)'a' ) && ( event.key.keysym.unicode <= (Uint16)'z' ) )

...reads "//If the key is a space"

I like the other tuts by the way...can't wait to see more :o)


One more thing...how would I go about allowing appostrophies, underscores, periods, etc.?


~Neith

[Edited by - Neith on October 1, 2006 1:44:35 PM]
while I'm at it...

I'm also trying to create the output buffer with SDL_TTF. Problem is, it only works with one line of text; I'm not sure on how to create new lines.


~Neith
Quote:Original post by Neith
while I'm at it...

I'm also trying to create the output buffer with SDL_TTF. Problem is, it only works with one line of text; I'm not sure on how to create new lines.


~Neith


Unfortunately you're going to have to cut up the string into sub strings, render surfaces each of those substrings then blit the rendered surfaces one after the other.

Or you can do it the way my bitmap font does it.

Learn to make games with my SDL 2 Tutorials

This topic is closed to new replies.

Advertisement