Well, I’m trying to get individual charaters - i was using SDL_GetKeyState(
… ) but it didn’t take into account modifier keys directly, and it was a
pain to try and “line up” all the modified key ascii codes. it wasn’t a bad
routine, but it also didn’t take into account the keyboard delays, and it
just turned out to be more of a pain then it was worth.
here’s a snippet of my code (with some minor debugging):
string Wait4Str( )
{
static string nullstr, tmp;
tmp.clear();
nullstr.clear();
char key;
key = cin.get( );
int ascii = key;
fprintf( stdout, "%c", key );
if( ( ascii >= 32 ) & ( ascii <= 255 ) ) {
input.append( 1, key );
return nullstr;
} else if( ascii == 8 ) {
input.resize( input.size() - 1 );
return nullstr;
} else if( ascii == 13 ) {
tmp = input;
input.clear();
return tmp;
} else if( ascii == 27 ) {
input.clear();
return nullstr;
}
// Part of my old code, excluding where i used the function to
fill the keyboard array…
/for( int ascii = 0; ascii < maxkey; ascii++ ) {
if( keyboard[ akeys[ key ] ] ) {
if( ((int)akeys[ key ] > 96) & ((int)akeys[ key ] < 123)
) {
//fprintf( stdout, “character pressed\n” );
if( ( keyboard[SDLK_RSHIFT] ) | (
keyboard[SDLK_LSHIFT] ) ) {
fprintf( stdout, “shift + character pressed\n”
);
input.append( 1, (char)akeys[ key ] - 32 );
} else {
input.append( 1, (char)akeys[ key ] );
}
} else {
input.append( 1, (char)akeys[ key ] );
}
}
}/
return nullstr;
}
This is what stdout looks like after i run the code (since it outputs the
characters to stdout.txt)
???
i typed that many keys, but they were actual letters…not these "?"
things
needless to say, i’m 80% frustrated.
to be perfectly honest, SDL’s input is only decent for gaming, so i had to
turn to other functions to try and get characters to build a string.
unforunately, since SDL enjoys obliterating most console functions, cin
doesn’t quite cut it.
has anyone written any functions that would act similar to cin? I don’t
mind writting the code, but if it’s already been done, why reinvent the
wheel, eh?
Interesting. I’ve never seen SDL cause any problems with cin. I’ve
seen Windows break it rather often though. What problems are you
talking about?–
Steaphan Greene
GPG public key:
http://www.cs.binghamton.edu/~sgreene/gpg.key.txthttp://www.cs.binghamton.edu/~sgreene/gpg.key.txt