Get ascii code from GdkEventKey-Keyval



Hi, everyone.

This is my first attempt to ask something here... err... hello ^_^

I've got Mandrake 8 (I think) "upgraded" to 9.2. This "upgrading" was made 
manually and not as well as I wanted, but that's another story. I'm saying 
this only to tell that I'm still programming with gdk 1.2 (or 1.3, I mean 
it's not 2.x).

Got a code like:

void key_pressed (GtkWidget *widget, GdkEvent *event, gpointer func_data)
{
        GdkEventKey *keyev;

        keyev = event;

        if (event->type == GDK_KEY_PRESS)
        {
                switch (keyev->keyval)

/* A thing I don't understand: you can't access a "keyval" for directly
"event", i've got to "move" event to a GdkEventKey before */

                {
                case GDK_Return: 
                        somewhere = ev_ok; somearg = 0; break;
                case GDK_Escape: 
                        somwehere = ev_cancel; somearg = 0; break;
                case GDK_F1:
                        somewhere = ev_help; somearg = 0; break;
                /* and so */
                }
        }
}

As you can see I Scan the "keyval". If it's a "special key" it stores 
"somewhere" = some "special" code for me, and somearg=0.

I want (if possible) that for each number / character, "somwehere" = 
ev_key  and  somearg = the ASCII code for this key (I want to print later 
sprintf (somearg) for instance).

That is (my english is not good and my brain worst), I want to "catch" the
key pressed (I've done it! Gracias, Miguel P!); but if the key is just a
letter/number (A, B, ..., Z, 5, 8) just store a "ev_key". I though about:

case GDK_f: somewhere = ev_ok; somearg = "f"; break;

but it's a little hard doing it for each letter, number... and I think 
it's far better readable any code as 

... default: 
       somewhere = ev_character; 
       somearg = get_ascii_code(evtecla->keyval);
       break;


Have i explained it clearly? I hope so!

Regards and thanks in advance,

.-:Namarie:-.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]