SDL and cin

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?

Alex~

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?On Fri, Mar 24, 2006 at 11:59:01AM -0500, Alex Barry wrote:

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?


Steaphan Greene
GPG public key: http://www.cs.binghamton.edu/~sgreene/gpg.key.txt
-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20060324/1e4013d8/attachment.pgp

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

Alex Barry <alex.barry gmail.com> writes:

Well, I’m trying to get individual charaters - i was using SDL_GetKeyState

Use SDL’s unicode functions with SDL_EnableUNICODE().
It makes getting string input a lot easier.

I have a tutorial on how to do it here:
lazyfooproductions.com/SDL_tutorials/lesson24/

Alex Barry wrote:

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 < sgreene at cs.binghamton.edu
<mailto:sgreene at cs.binghamton.edu>>
GPG public key: http://www.cs.binghamton.edu/~sgreene/gpg.key.txt
<http://www.cs.binghamton.edu/%7Esgreene/gpg.key.txt>

http://www.newhost.ru
http://www.nm.ru/cgi-bin/denban.cgi?ban_id=39&ban_url=http://www.newhost.ru

  • ??? ??? ??? ??? !!!


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Hi,
It is a bad idea to mix C++ and C i/o streams. Try replacing printf with
cout.

Hi,
It is a bad idea to mix C++ and C i/o streams. Try replacing printf with
cout.
when sdl is running, since it takes out the console, cout does not work -
that’s why i’m using the default filestream, stdout

Alex Barry wrote:

Hi,
It is a bad idea to mix C++ and C i/o streams. Try replacing printf with
cout.
when sdl is running, since it takes out the console, cout does not
work - that’s why i’m using the default filestream, stdout

C++ and C library streams both use ‘read (0, … )’ & 'write (1, … )'
system calls. So if ‘printf’ works, ‘cout’ works too and vice versa.
Maybe you’ve forgot to add newline and that’s why contents of the buffer
are not flushed to the screen.

PS: please excuse me for the spam from the mailserver in my previous
message.